简体   繁体   English

RPC服务器在BackgroundMediaPlayer.SendMessageToBackground上不可用

[英]The RPC server is unavailable exception on BackgroundMediaPlayer.SendMessageToBackground

Im making a windows phone 8.1 app. 我正在制作Windows Phone 8.1应用。 It sends a playlist to BackgroundMediaPlayer, and player starts playing somgs. 它将播放列表发送到BackgroundMediaPlayer,然后播放器开始播放somgs。 But sometimes I get an exception "The RPC server is unavailable" when sending message with BackgroundMediaPlayer.SendMessageToBackground, and the only thing can fix it is restarting app. 但是有时在使用BackgroundMediaPlayer.SendMessageToBackground发送消息时,出现异常“ RPC服务器不可用”的情况,唯一可以解决的问题是重新启动应用程序。 Im testing it on windows 10 mobile and not sure if this problems exists on WP8.1, but no problems in WP8.1 emulator 我在Windows 10移动版上对其进行了测试,不确定WP8.1是否存在此问题,但WP8.1仿真器中没有问题

I ran into a similar problem working in a Windows 10 Universal project, except I had no successful interaction with BackgroundMediaPlayer at all. 我在Windows 10 Universal项目中工作时遇到了类似的问题,除了我没有与BackgroundMediaPlayer进行成功交互之外。 The cause was my background audio task was not being started; 原因是我的背景音频任务还没有开始。 after ensuring it started I could successfully access BackgroundMediaPlayer.Current member, and use BackgroundMediaPlayer.SendMessageToBackground etc. It was a combination of the official Microsoft sample for Background Audio actually working, and this post by another member that led me to the solution. 确保它启动后,我可以成功访问BackgroundMediaPlayer.Current成员,并使用BackgroundMediaPlayer.SendMessageToBackground等。这是结合了Microsoft官方用于Background Audio的示例的实际效果,以及另一位成员的这篇帖子使我找到了解决方案。

It sounds like your initial interaction with the BackgroundMediaPlayer working for a time, but then it stops working. 听起来您与BackgroundMediaPlayer的初始交互工作了一段时间,但随后停止了工作。 Could it be that it's being shutdown or suspended prematurely? 可能是它正在关闭或过早挂起? Are you obtaining a deferral in the task's Run method and storing it? 您是否在任务的Run方法中获得了延迟并存储了它? Hooking up event handlers for TaskCompleted and OnCancelled after you have obtained the deferral? 获取延期后,为TaskCompleted和OnCancelled连接事件处理程序吗? Is it possible BackgroundMediaPlayer.Shutdown() is being called somewhere accidentally? 是否有可能在某个地方意外调用BackgroundMediaPlayer.Shutdown()?

I originally wrote this answer before I realised that the OP was playing audio successfully, and facing this problem only after the program had been running awhile. 我最初写这个答案是在我意识到OP可以成功播放音频之前,并且只有在程序运行了一段时间后才遇到此问题。 The remainder of my original answer is as follows (it might help someone with a similar problem): 我原始答案的其余部分如下(它可能会帮助遇到类似问题的人):

My background task wasn't starting because it was within a Class Library instead of a Windows Runtime Component (This matters, I think, because the process that provides background audio, Windows.Media.BackgroundPlayback.exe, is a native application and must rely on interop to interact with the tasks we write (and it loads our task as part of its process, not part of our foreground app that uses the task); this Microsoft guide does specifically state "Windows Runtime Component" when advising placing all background tasks in a separate project ). 我的后台任务没有启动,因为它位于类库而不是Windows运行时组件中(我认为这很重要,因为提供背景音频Windows.Media.BackgroundPlayback.exe的过程是本机应用程序,必须依靠在互操作时与我们编写的任务进行交互(并且将任务作为进程的一部分而不是使用该任务的前台应用程序的一部分进行加载);当建议放置所有后台任务时,此Microsoft指南会特别声明“ Windows运行时组件”在一个单独的项目中 )。

By changing my Class Library to a Windows Runtime Component (which involved making the task class sealed, and the other restrictions entailed), the IBackgroundTask.Run method was invoked, I obtained a deferral, and all my calls to interact with the BackgroundMediaPlayer began working properly. 通过将我的类库更改为Windows运行时组件(这涉及密封任务类,并带来其他限制),调用了IBackgroundTask.Run方法,获得了延期,并且所有与BackgroundMediaPlayer进行交互的调用都开始起作用正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM