如何知道我的应用程序是否在后台播放音乐?

编程入门 行业动态 更新时间:2024-10-26 02:34:02
本文介绍了如何知道我的应用程序是否在后台播放音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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 } } }

更多推荐

如何知道我的应用程序是否在后台播放音乐?

本文发布于:2023-07-11 09:05:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1093517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   后台   音乐

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!