Пример #1
0
        /// <summary>
        /// Loads the specified file into the player.
        /// </summary>
        /// <param name="fileName">Path to the music file.</param>
        /// <returns>Boolean</returns>
        public async Task <bool> Load(string fileName)
        {
            StorageFile file = await StorageFile.GetFileFromPathAsync(fileName);

            if (file != null)
            {
                string sPath = file.Path;
                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                await Stop();

                await Task.Run(() =>
                {
                    handle      = ManagedBass.Bass.CreateStream(sPath, 0, 0, BassFlags.AutoFree | BassFlags.Float);
                    PlayerState = PlayerState.Stopped;
                    MediaStateChanged(this, new MediaStateChangedEventArgs(PlayerState.Stopped));
                    Bass.ChannelSetSync(handle, SyncFlags.End | SyncFlags.Mixtime, 0, _sync);
                    InitializeExtensions(fileName);
                    CurrentlyPlayingFile  = file.Path;
                    CoreWindowLogic logic = new CoreWindowLogic();
                    logic.Stringify();
                });

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// Loads the specified file into the player.
        /// </summary>
        /// <param name="fileName">Path to the music file.</param>
        /// <returns>Boolean</returns>
        public async Task <bool> Load(Mediafile mp3file)
        {
            if (mp3file != null)
            {
                string sPath = mp3file.Path;
                await Stop();

                await Task.Run(() =>
                {
                    handle      = ManagedBass.Bass.CreateStream(sPath, 0, 0, BassFlags.AutoFree | BassFlags.Float);
                    PlayerState = PlayerState.Stopped;
                    Length      = Bass.ChannelBytes2Seconds(handle, Bass.ChannelGetLength(handle));
                    MediaStateChanged(this, new MediaStateChangedEventArgs(PlayerState.Stopped));
                    Bass.ChannelSetSync(handle, SyncFlags.End | SyncFlags.Mixtime, 0, _sync);
                    CurrentlyPlayingFile = mp3file;
                    CoreWindowLogic.UpdateSmtc();
                    CoreWindowLogic.Stringify();
                });

                Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Remove(CoreMethods.CurrentFileToken);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
        /// <summary>
        /// Loads the specified file into the player.
        /// </summary>
        /// <param name="fileName">Path to the music file.</param>
        /// <returns>Boolean</returns>
        public async Task <bool> Load(Mediafile mp3file)
        {
            if (mp3file != null && mp3file.Length != "00:00")
            {
                try
                {
                    string sPath = mp3file.Path;
                    await Stop();

                    await Task.Run(() =>
                    {
                        Bass.Stop();
                        Bass.Start();

                        handle      = ManagedBass.Bass.CreateStream(sPath, 0, 0, BassFlags.AutoFree);
                        PlayerState = PlayerState.Stopped;
                        Length      = Bass.ChannelBytes2Seconds(handle, Bass.ChannelGetLength(handle));
                        InitializeExtensions(sPath);
                        MediaStateChanged(this, new MediaStateChangedEventArgs(PlayerState.Stopped));
                        Bass.ChannelSetSync(handle, SyncFlags.End | SyncFlags.Mixtime, 0, _sync);
                        CurrentlyPlayingFile = mp3file;
                        CoreWindowLogic.UpdateSmtc();
                        CoreWindowLogic.Stringify();

                        //
                    });

                    return(true);
                }
                catch (Exception ex)
                {
                    await NotificationManager.ShowAsync(ex.Message + "||" + mp3file.OrginalFilename);
                }
            }
            else
            {
                string error = "The file " + mp3file.OrginalFilename + " is either corrupt, incomplete or unavailable. \r\n\r\n Exception details: No data available.";
                if (IgnoreErrors == false)
                {
                    CoreWindowLogic.ShowMessage(error, "File corrupt");
                }
                else
                {
                    await NotificationManager.ShowAsync(error);
                }
            }
            return(false);
        }