Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
782 views
in Technique[技术] by (71.8m points)

uwp - Xbox app not allowed enough time to halt video player when backgrounded

I have run into a perplexing problem with a video streaming app I develop. It is a UWP/PWA (JavaScript) app running web content and using an HTML5 video player with a streaming manager we get from a 3rd party. Every single time the application is put into the background (i.e. the user navigates away to the Xbox home screen), an error occurs that seems related to the streaming manager calling an Edge media extension method of some sort after it has entered a suspended state. As part of our process for when the backgrounding event occurs, we call an asynchronous method that stops video playback.

After some research, I discovered a permission for the app that I felt optimistic about. Given my suspicion that the problem relates to the async stop method not completing quickly enough, I thought checking off "Background Media Playback" in the app manifest might resolve the issue. After all, the description purports to allow media to continue operating even after backgrounding:

The backgroundMediaPlayback capability changes the behavior of the media-specific APIs like the MediaPlayer and AudioGraph classes to enable media playback while your app is in the background. All active audio streams will no longer mute, but will continue to be audible when an app transitions to the background. Additionally, app lifetime will be extended automatically while playback is occurring. https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations

Sure enough, the error went away after applying this permission to the app. However, I soon noticed it had side effects.

The first side effect was that I could hear audio continuing even after putting the app into the background, but I expected this since the permission is most typically used for apps like Pandora where continued audio playback is a desired feature. Easy fix to mute the player prior to calling its stop method.

The second side-effect turned out to be a blocker. I noticed that reliably, after about 6 seconds in the background, the Xbox always terminates the app. I was perplexed thinking I had introduced a runtime error somehow, but I could not detect any even with Visual Studio debugger attached. After some further research, I found out there are some limitations on the permission I used.

  1. The app cannot use more than 125 MB of memory
  2. Media playback must be allowed to continue

What seems to happen is that once the app stops playback, the Xbox determines that it is time to terminate the app instead of putting it into a suspended state as it would normally do.

I cannot seem to figure out a way around this problem. To resolve this error, I need to somehow give the async stop method enough time to do what it needs to do, but I wouldn't want to sacrifice the ability of the app to enter a suspended state.

It would be nice to somehow tell the platform to hold off a little on suspending the app until the async operation completes, but everything else I have tried (ex: requesting extended execution) has been a crapshoot. What I need to do seems simple enough, but this bug has proven infuriatingly stubborn to squash.

question from:https://stackoverflow.com/questions/65853809/xbox-app-not-allowed-enough-time-to-halt-video-player-when-backgrounded

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...