开发落网电台windows phone 8应用的计划(4)
2014-03-13 22:00
323 查看
昨天把应用的后台播放代理搞定了,但是运行的状况不太好,在网络不好的情况下有时候会崩溃,更多的时候是没有声音。
现在的任务就有两个了:一个是搞定网络,这部分还没有一个很好的计划,因为前台UI和后台播放代理的通信我还没有想到很好的办法,能想到的方法是借助backgroundPlayer的调用来解决,不过这就限制了后期功能的扩展,不过可能就先这么做吧;第二个是怎么处理好缓冲的问题。
先把后台代理放在这上面吧,还是简单版本。参照了csdn的做法,没有做网络。
View Code
现在的任务就有两个了:一个是搞定网络,这部分还没有一个很好的计划,因为前台UI和后台播放代理的通信我还没有想到很好的办法,能想到的方法是借助backgroundPlayer的调用来解决,不过这就限制了后期功能的扩展,不过可能就先这么做吧;第二个是怎么处理好缓冲的问题。
先把后台代理放在这上面吧,还是简单版本。参照了csdn的做法,没有做网络。
using System; using System.Diagnostics; using System.Windows; using Microsoft.Phone.BackgroundAudio; using System.Collections.Generic; using System.Threading; namespace LuooAudioPlayerAgent { public class AudioPlayer : AudioPlayerAgent { #region 字段 static int currentTrackNumber=0; public static int totalNumber; private static List<AudioTrack> playList=new List<AudioTrack>() { new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/01.mp3",UriKind.Absolute),"1","","",null), new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/02.mp3",UriKind.Absolute),"2","","",null), //new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/03.mp3",UriKind.Absolute),"","","",null), //new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/04.mp3" , UriKind.Absolute) , "" , "" , "" , null) }; #endregion static AudioPlayer() { //GetList(); Deployment.Current.Dispatcher.BeginInvoke(delegate { Application.Current.UnhandledException += UnhandledException; }); } #region 出现未处理的异常时执行的代码 private static void UnhandledException( object sender , ApplicationUnhandledExceptionEventArgs e ) { if(Debugger.IsAttached) { // 出现未处理的异常;强行进入调试器 Debugger.Break(); } } #endregion protected override void OnPlayStateChanged( BackgroundAudioPlayer player , AudioTrack track , PlayState playState ) { switch(playState) { case PlayState.TrackEnded: PlayNextTrack(player); break; case PlayState.TrackReady: player.Play(); break; } NotifyComplete(); } protected override void OnUserAction( BackgroundAudioPlayer player , AudioTrack track , UserAction action , object param ) { switch(action) { case UserAction.Play: if(player.Track==null) player.Track=playList[currentTrackNumber]; player.Play(); break; case UserAction.Pause: player.Pause(); break; case UserAction.SkipNext: PlayNextTrack(player); break; case UserAction.SkipPrevious: PlayPreviousTrack(player); break; //case UserAction.FastForward: // GetList(); // break; } NotifyComplete(); } #region control private void PlayNextTrack( BackgroundAudioPlayer player ) { if(++currentTrackNumber >=playList.Count) { currentTrackNumber = 0; } player.Track=playList[currentTrackNumber]; } private void PlayPreviousTrack( BackgroundAudioPlayer player ) { if(--currentTrackNumber < 0) { currentTrackNumber = playList.Count - 1; } player.Track=playList[currentTrackNumber]; } #endregion protected override void OnError( BackgroundAudioPlayer player , AudioTrack track , Exception error , bool isFatal ) { if(isFatal) { Abort(); } else { NotifyComplete(); } } protected override void OnCancel() { } public static void GetList() { playList.Add(new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/04.mp3" , UriKind.Absolute) , "4" , "" , "" , null)); //playList.Add(new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/02.mp3" , UriKind.Absolute) , "" , "" , "" , null)); //playList.Add(new AudioTrack(new Uri("http://luoo.800edu.net/low/luoo/radio587/03.mp3" , UriKind.Absolute) , "" , "" , "" , null)); //totalNumber=playList.Count; } } }
View Code
相关文章推荐
- 开发落网电台windows phone 8应用的计划(6)
- 开发落网电台windows phone 8应用的计划(9)
- 开发落网电台windows phone 8应用的计划(7)
- 开发落网电台windows phone 8应用的计划(3)
- 开发落网电台windows phone 8应用的计划(2)
- 开发落网电台windows phone 8应用的计划(1)
- 开发落网电台windows phone 8应用的计划(5)
- 开发落网电台windows phone 8应用的计划(10)-----收尾
- 开发落网电台windows phone 8应用的计划(8)
- Windows phone 应用开发[4]-应用发布
- 人人网 Windows Phone 7 应用开发起步
- Windows phone 应用开发[6]-Managed Extensibility Framework应用程序扩展
- Windows phone 应用开发[7]-MEF For Windows phone
- .NET平台开发Windows Phone 7、iPhone及Android应用
- Windows phone 应用开发[8]-体验PhoneGap
- 计划写一个MyEclipse6.0开发Spring应用的简单教程。
- 《深入浅出Windows Phone 8应用开发》
- Windows phone 应用开发[8]-体验PhoneGap
- 《Windows Phone 7入门经典之使用Silverlight和XNA开发Windows Phone应用》书评