我正在使用BackgroundAudio类,我的应用程序要知道是否正在播放时,立即将我发送到播放器页面,但是无法正常工作,我有此代码,但是我不知道该位置是否在主页文件中或App.cs文件以识别是否在播放
I'm using BackgroundAudio classmy App to make know if is playing send me imediatly to the player page but the doesn't work i have this code but i dont know where place if in the main page file or App.cs file to recognize if is playing or not
if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState) { NavigationService.Navigate(new Uri("/PlayerPage.xaml", UriKind.Relative)); } else { // do nothing }推荐答案
您可以将其放在默认启动页面的OnNavigatedTo()函数中.
You can put this in OnNavigatedTo() function of your default startup page.
提示:如果您使用的是SDK 8.0,请确保未连接调试器.我注意到,连接调试器后,重新启动应用程序时,后台播放器实例将停止.
tip: If you're using SDK 8.0 ... make sure the debugger is NOT attached. I notice that when the debugger is attached it the background player instance stops when the app is re-launched.
例如:
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New) { if (PlayState.Playing == BackgroundAudioPlayer.Instance.PlayerState) { Dispatcher.BeginInvoke(() => { NavigationService.Navigate(new Uri("/PlayerPage.xaml", UriKind.Relative)); }); } else { //do nothing } } }
更多推荐
如何知道我的应用程序是否在后台播放音乐?
发布评论