I created an radio app for windows 10 using mediaElement for audio output with AudioCategory = BackgroundCapableMedia but whenever I minimize the app on desktop or mobile the audio stops playing. So how do I keep the audio alive after I minimize? And all examples I find is for 8.1 silverlight applications
You need to implement a Background Task to keep audio alive when your application is minimized.
You can find a sample which targets Windows 10 on github. The project is splitted in 3 parts (a/ your main application b/ the background task and c/ code shared between the two first projects)
Background audio sample
In addition, you can find documentation associated to this sample on MSDN.
Background Audio
Please let me know if you need additional information.
Related
I m working on this project, the client gave me the task to design the UI and embed videos. The backend code of that application is complete according to the client and the backend code is really poorly written with zero optimization.
The application is working perfectly, the application starts the main form loads axWindowsMediaPlayer form with it self and axWindowsMediaPlayer loads videos through resources. The issue is that in the beginning of each video the media player blinks, like if the playlist have 3 videos it'll blink 3 times and if I run the axWindowsMediaPlayer form separately it doesn't blink at all.
I've no idea what to do here.
Standart windows media player control is way too dated. It's basically good for nothing at this point. I'd just open nuget package list and look for any video player control. In case there is none, you can always just add a chromium-based webview element and play your video in there.
I'm creating an app (Windows Runtime) that requires sound to run in the background (even when the phone is locked) so I set the BackgroundMediaPlayer's isLoopingEnabled property to true in the background task but when I play back the audio in the app there is about a 1 second gap between the audio finishing and starting again.
I've also tried setting the position property of the player to 0 on the MediaEnded event but that bared the same result.
Is there any way to achieve gapless looping using the BackgroundMediaPlayer in Windows Phone 8.1???
There's no workaround for this feature AFAIK but Gapless Audio support is coming with upcoming Windows 10.
I am working with Windows Phone 8.1 and C#.
By following Microsoft's MSDN sample (available at: http://code.msdn.microsoft.com/windowsapps/BackgroundAudio-63bbc319) to create an audio player, I tried to integrate it into my project. However, while the code works fine in Microsoft's sample, it does not work as intended after I integrate it into my project.
I'll copy and paste the files are likely to contain the issue. Constants.cs, ApplicationSettingsHelper.cs and MyPlaylistManager.cs remain the same as in the sample (which you can look at by clicking the link above and hitting the "Browse code" tab).
When I run the following project, it throws the following error: "Background Audio Task didn't start in expected time". If I change the bool result = SererInitialized.WaitOne(2000); block of code (in StartBackgroundAudio() to bool result = true;, it simply prints "Background Audio Task initialized" in the console and then stops.
Page.xaml.cs
http://pastebin.com/L2zxzJKv
BackgroundAudio.cs
http://pastebin.com/zR6uzBf3
I don't understand what I am doing wrong. I ended up undoing all my changes and simply use the exact same code from the sample in the project. I added the extensions in the appmanifest.
I have created a sample project to help someone solve the problem and answer this question. You can find it at https://onedrive.live.com/redir?resid=ED2ED8732D8D457E!132&authkey=!AFBrZi5oI3k2zmU&ithint=file%2czip
The ZIP file you provided only has one project in the solution. The background audio task needs to be its own separate Windows Runtime Component project in the solution. Please look at the sample solution again and make sure that you have set up your solution correctly.
The reason why your background audio task needs to be in a separate project is because all background tasks need to be in a separate project, and background tasks will run in a separate process than your foreground app. This is so that if the OS suspends or terminates your app (i.e. you switched to another app) then your background audio task will continue to run and play audio even though your app has been suspended. You will then need to communicate between the background audio task and foreground process by passing messages between the processes (see SendMessageToForeground and SendMessageToBackground).
Apps will always be suspended by the OS when put in the background, therefore you need a separate lightweight background task process that has special permission to run in the background for the purpose of playing music.
These pages are quite helpful at explaining all of the concepts:
Overview: Background audio (Windows Phone Store apps)
How to play audio in the background (XAML)
I am working on an app which displays videos and am running into an issue where the machine goes to sleep after hitting the sleep time limit while a video is playing. Is there a way to disable this behavior in a Windows 8 Metro application?
You should use the DisplayRequest class, specifically DisplayRequest.RequestActive for this purpose. You must also remember to call DisplayRequest.RequestRelease once you are done to allow the display to sleep, for example, if you are not actively playing the movie, or in a menu screen, etc.
What would be the easiest way to have a music file included in the App as looped background music while the app is running and the music pauses if the app is suspended and starts up again when the app is brought back to foreground. Don't care about playing for the devices iTunes/Music catalog just one or more included music files within the App bundle.
I don't know if it's the easiest way, but there is some sample code in TweetStation to play audio in your app.