當前位置: 首頁>>代碼示例>>C#>>正文


C# BackgroundAudioPlayer類代碼示例

本文整理匯總了C#中BackgroundAudioPlayer的典型用法代碼示例。如果您正苦於以下問題:C# BackgroundAudioPlayer類的具體用法?C# BackgroundAudioPlayer怎麽用?C# BackgroundAudioPlayer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BackgroundAudioPlayer類屬於命名空間,在下文中一共展示了BackgroundAudioPlayer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnNavigatedTo

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            backgroundAudioPlayer= BackgroundAudioPlayer.Instance;
            using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!storage.FileExists("Making love without nothing at all.mp3"))
                {
                    StreamResourceInfo resource = Application.GetResourceStream(new Uri("Assets/Making love without nothing at all.mp3", UriKind.Relative));
                    using (IsolatedStorageFileStream file = storage.CreateFile("Making love without nothing at all.mp3"))
                    {
                        int chunkSize = 4096;
                        byte[] bytes = new byte[chunkSize];
                        int byteCount;
                        while ((byteCount = resource.Stream.Read(bytes, 0, chunkSize)) > 0)
                        {
                            file.Write(bytes, 0, byteCount);
                        }
                    }
                }
            }

            backgroundAudioPlayer.PlayStateChanged += backgroundAudioPlayer_PlayStateChanged;


            base.OnNavigatedTo(e);
        }
開發者ID:peepo3663,項目名稱:WindowsPhone8,代碼行數:26,代碼來源:MainPage.xaml.cs

示例2: OnUserAction

        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            switch (action)
            {
                case UserAction.Play:
                    if (PlayState.Playing != player.PlayerState)
                    {
                        player.Play();
                    }
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;

                case UserAction.Pause:
                    if (PlayState.Playing == player.PlayerState)
                    {
                        player.Pause();
                    }
                    break;
                case UserAction.Rewind:
                  player.Position = player.Position.Subtract(new TimeSpan(0,0,10));
                    break;

                case UserAction.FastForward:
                  player.Position = player.Position.Add(new TimeSpan(0,0,10));
                    break;
            }

            NotifyComplete();
        }
開發者ID:juhariis,項目名稱:Windows-Phone-Starter-Kit-for-Podcasts,代碼行數:32,代碼來源:AudioPlayer.cs

示例3: OnUserAction

        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
        {
            ShellTile mainTile = ShellTile.ActiveTiles.FirstOrDefault();
            switch (action)
            {
                case UserAction.Play:
                    if (PlayState.Paused == player.PlayerState)
                    {
                        player.Play();

                        mainTile.Update(new StandardTileData
                        {
                            BackContent = "Play"
                        });

                    }
                    break;

                case UserAction.Pause:
                    player.Pause();

                    mainTile.Update(new StandardTileData
                    {
                        BackContent = "Pause"
                    });
                    break;
            }
            NotifyComplete();
        }
開發者ID:OlivierRiberi,項目名稱:3NET-SimpleRadio,代碼行數:29,代碼來源:AudioPlayer.cs

示例4: OnPlayStateChanged

        /// <summary>
        /// playstate 更改時調用,但 Error 狀態除外(參見 OnError)
        /// </summary>
        /// <param name="player">BackgroundAudioPlayer</param>
        /// <param name="track">在 playstate 更改時播放的曲目</param>
        /// <param name="playState">播放機的新 playstate </param>
        /// <remarks>
        /// 無法取消播放狀態更改。即使應用程序
        /// 導致狀態自行更改也會提出這些更改,假定應用程序已經選擇了回調。
        ///
        /// 值得注意的 playstate 事件:
        /// (a) TrackEnded: 播放器沒有當前曲目時激活。代理可設置下一曲目。
        /// (b) TrackReady: 音軌已設置完畢,現在可以播放。
        ///
        /// 隻在代理請求完成之後調用一次 NotifyComplete(),包括異步回調。
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    //player.Track = GetPreviousTrack();
                    //player.Track = GetNextTrack();
                    PlayNextTrack(player);
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: 在此處理關機狀態(例如保存狀態)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
開發者ID:vicalloy,項目名稱:lb.ting,代碼行數:51,代碼來源:AudioPlayer.cs

示例5: OnPlayStateChanged

        /// <summary>
        ///     Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        ///     Play State changes cannot be cancelled. They are raised even if the application
        ///     caused the state change itself, assuming the application has opted-in to the callback.
        ///     Notable playstate events:
        ///     (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        ///     (b) TrackReady: an audio track has been set and it is now ready for playack.
        ///     Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            Debug.WriteLine("OnPlayStateChanged() playState " + playState);

            switch (playState)
            {
                case PlayState.TrackEnded:
                    player.Track = GetPreviousTrack();
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
開發者ID:henricj,項目名稱:HttpClientBackgroundAudio,代碼行數:49,代碼來源:AudioPlayer.cs

示例6: OnPlayStateChanged

        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        /// 
        /// Notable playstate events: 
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        /// 
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    player.Track = GetNextTrack();
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    _playlistHelper.SetAllTracksToNotPlayingAndSave();
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
開發者ID:EchoDemon,項目名稱:MediaBrowser.WindowsPhone,代碼行數:50,代碼來源:AudioPlayer.cs

示例7: OnUserAction

 /// <summary>
 /// Called when the user requests an action using system-provided UI and the application has requesed
 /// notifications of the action
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track playing at the time of the user action</param>
 /// <param name="action">The action the user has requested</param>
 /// <param name="param">The data associated with the requested action.
 /// In the current version this parameter is only for use with the Seek action,
 /// to indicate the requested position of an audio track</param>
 /// <remarks>
 /// User actions do not automatically make any changes in system state; the agent is responsible
 /// for carrying out the user actions if they are supported
 /// </remarks>
 protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action, object param)
 {
     if (action == UserAction.Play)
         player.Play();
     else if (action == UserAction.Pause)
         player.Pause();
     NotifyComplete();
 }
開發者ID:whrxiao,項目名稱:Windows-Phone-7-In-Action,代碼行數:22,代碼來源:AudioPlayer.cs

示例8: PlayPreviousTrack

        private void PlayPreviousTrack(BackgroundAudioPlayer player)
        {
            if (--currentTrackNumber < 0)
            {
                currentTrackNumber = _playList.Count - 1;
            }

            PlayTrack(player);
        }
開發者ID:abuhmead1987,項目名稱:Presentations,代碼行數:9,代碼來源:AudioPlayer.cs

示例9: PlayNextTrack

        private void PlayNextTrack(BackgroundAudioPlayer player)
        {
            if (++currentTrackNumber >= _playList.Count)
            {
                currentTrackNumber = 0;
            }

            PlayTrack(player);
        }
開發者ID:abuhmead1987,項目名稱:Presentations,代碼行數:9,代碼來源:AudioPlayer.cs

示例10: OnPlayStateChanged

 protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
 {
     switch (playState)
     {
         case PlayState.TrackReady:
             player.Play();
             break;
     }
     NotifyComplete();
 }
開發者ID:OlivierRiberi,項目名稱:3NET-SimpleRadio,代碼行數:10,代碼來源:AudioPlayer.cs

示例11: OnError

 /// <summary>
 /// Called whenever there is an error with playback, such as an AudioTrack not downloading correctly
 /// </summary>
 /// <param name="player">The BackgroundAudioPlayer</param>
 /// <param name="track">The track that had the error</param>
 /// <param name="error">The error that occured</param>
 /// <param name="isFatal">If true, playback cannot continue and playback of the track will stop</param>
 /// <remarks>
 /// This method is not guaranteed to be called in all cases. For example, if the background agent
 /// itself has an unhandled exception, it won't get called back to handle its own errors.
 /// </remarks>
 protected override void OnError(BackgroundAudioPlayer player, AudioTrack track, Exception error, bool isFatal)
 {
     if (isFatal)
     {
         Abort();
     }
     else
     {
         NotifyComplete();
     }
 }
開發者ID:vladk1,項目名稱:Kaizen,代碼行數:22,代碼來源:AudioPlayer.cs

示例12: OnPlayStateChanged

        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        ///
        /// Notable playstate events:
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        ///
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackEnded:
                    //player.Track = GetPreviousTrack();
                    player.Track = null;
                    break;
                case PlayState.TrackReady:
                    player.Play();
                    connectedEvent.Set();

                    if (track != null && track.Tag != null)
                    {
                        var data = track.Tag.ToString().Split('$');
                        var url = data[data.Length - 1];
                        var title = data[1];
                        var type = data[2];

                        //#region from http://stackoverflow.com/questions/7159900/detect-application-launch-from-universal-volume-control
                        //MediaHistoryItem nowPlaying = new MediaHistoryItem();
                        //nowPlaying.Title = title;
                        //nowPlaying.PlayerContext.Add("station", title);
                        //MediaHistory.Instance.NowPlaying = nowPlaying;
                        //#endregion
                    }
                    break;
                case PlayState.Shutdown:
                    // TODO: Handle the shutdown state here (e.g. save state)
                    break;
                case PlayState.Unknown:
                    break;
                case PlayState.Stopped:
                    break;
                case PlayState.Paused:
                    break;
                case PlayState.Playing:
                    break;
                case PlayState.BufferingStarted:
                    break;
                case PlayState.BufferingStopped:
                    break;
                case PlayState.Rewinding:
                    break;
                case PlayState.FastForwarding:
                    break;
            }

            NotifyComplete();
        }
開發者ID:Amrykid,項目名稱:Hanasu,代碼行數:66,代碼來源:AudioPlayer.cs

示例13: OnPlayStateChanged

        /// <summary>
        /// Called when the playstate changes, except for the Error state (see OnError)
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time the playstate changed</param>
        /// <param name="playState">The new playstate of the player</param>
        /// <remarks>
        /// Play State changes cannot be cancelled. They are raised even if the application
        /// caused the state change itself, assuming the application has opted-in to the callback.
        /// 
        /// Notable playstate events: 
        /// (a) TrackEnded: invoked when the player has no current track. The agent can set the next track.
        /// (b) TrackReady: an audio track has been set and it is now ready for playack.
        /// 
        /// Call NotifyComplete() only once, after the agent request has been completed, including async callbacks.
        /// </remarks>
        protected override void OnPlayStateChanged(BackgroundAudioPlayer player, AudioTrack track, PlayState playState)
        {
            switch (playState)
            {
                case PlayState.TrackReady:
                    // Wiedergabe wurde in PlayTrack() bereits festgelegt
                    player.Play();
                    break;
                case PlayState.TrackEnded:
                    PlayNextTrack(player);
                    break;
            }

            NotifyComplete();
        }
開發者ID:GregOnNet,項目名稱:WP8BookSamples,代碼行數:31,代碼來源:AudioPlayer.cs

示例14: OnUserAction

        /// <summary>
        /// Called when the user requests an action using system-provided UI and the application has requesed
        /// notifications of the action
        /// </summary>
        /// <param name="player">The BackgroundAudioPlayer</param>
        /// <param name="track">The track playing at the time of the user action</param>
        /// <param name="action">The action the user has requested</param>
        /// <param name="param">The data associated with the requested action.
        /// In the current version this parameter is only for use with the Seek action,
        /// to indicate the requested position of an audio track</param>
        /// <remarks>
        /// User actions do not automatically make any changes in system state; the agent is responsible
        /// for carrying out the user actions if they are supported
        /// </remarks>
        protected override void OnUserAction(BackgroundAudioPlayer player, AudioTrack track, UserAction action,
                                             object param)
        {
            switch (action)
            {
                case UserAction.Play:
                    playTrack(player);
                    break;

                case UserAction.Stop:
                    player.Stop();
                    break;
            }

            NotifyComplete();
        }
開發者ID:woodgate,項目名稱:MegastrazWP7,代碼行數:30,代碼來源:AudioPlayer.cs

示例15: PlayPreviousTrack

        private void PlayPreviousTrack(BackgroundAudioPlayer player)
        {
            if (_playList.Count == 0)
            {
                loadPlaylist();
            }
            else if (--currentTrackNumber < 0)
            {
                currentTrackNumber = _playList.Count - 1;
                StorageUtility.writeStringToFile(IsolatedStorageFile.GetUserStoreForApplication(),
                "CurrentTrackNumber.txt",
                currentTrackNumber.ToString(CultureInfo.InvariantCulture));
            }

            player.Track = _playList[currentTrackNumber];
            player.Play();
        }
開發者ID:lonkly,項目名稱:StereomoodWP7,代碼行數:17,代碼來源:AudioPlayer.cs


注:本文中的BackgroundAudioPlayer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。