I'm creating a Windows Phone 8.1 app to play music and video from URIs. I first used a MediaElement control, to play media content.
However I can't play video or audio when my app is switched to background. I've implemented this (with BackgroundMediaPlayer) but this sample can only play audio, and I want my app to play video too.
I've searched a lot on the Internet, but I couldn't find the answer I'm looking for. So my question is : How can I play video in my app when it's switched to background?
If BackgroundMediaPlayer can't play video files in background I am almost sure there is no way to do it. That looks a little bit strange to play video in background.
But if your app is switched to the foreground, you can continue play video. Just save the last file in the mostRecentlyUsedList to have permissions to access this file the next time the app is opened.
Windows.Storage.AccessCache.StorageApplicationPermissions.MostRecentlyUsedList.Add(yourfile);
And later you can get it with:
String lastfilemruFirstToken = StorageApplicationPermissions.MostRecentlyUsedList.Entries.FirstOrDefault().Token;
StorageFile lastfile = await StorageApplicationPermissions.MostRecentlyUsedList.GetFileAsync(lastfilemruFirstToken);
The position you can get and set with the MediaElement.Position property
Related
I want to join multiple AAC audio files which are audio recording in real in a Windows Phone 8.1 app. Actually I want pause/resume feature in audio recording. In MP3 encoding I can simply join the buffer to have composition of audio files but in case of AAC it's not working. MP3 encoding profile is not available in Windows Phone 8.1. I thought MediaComposition will help me to stitch the audio recording, but I am getting exceptions it it.
I tried first to create MediaClip object from audio file but I am getting ArgumentException with message Source can not be audio file. Then I tried to create BackgroundAudioTrack object from audio file & added in MediaComposition. Then I tried to set source to MediaElement with these methods cvMediaElement.SetMediaStreamSource(comp.GenerateMediaStreamSource()); and cvMediaElement.SetMediaStreamSource(comp.GeneratePreviewMediaStreamSource(100, 100));, both throws ArgumentException with message The parameter is incorrect. Any one here to point me out to correct way?
I know this is an old question, but figured I would answer for you and others in case it is found during search.
As you noticed, audio clips are not supported directly in MediaComposition in Windows Phone 8.1. This has been fixed for Windows 10 (and MediaComposition itself is now part of the Universal Windows Platform so you can use it on many platforms).
For Windows Phone 8.1, the issue is likely tied to the fact that BackgroundAudioTracks don't dictate the length of "content" (per se) of the composition. To do this, you will likely need to add a blank MediaClip first. You can create a MediaClip from the color black for instance (MediaClip.CreateFromColor) and have it be as long as the total length of the background audio tracks. That should then let it work as expected on Windows Phone 8.1.
If you continue to run into any of these issues if you give it a whirl on Windows 10, please let me know and I can get some bugs filed :).
I need to play a list of videos using a player framework. When I play the first video, I need the second video to start loading in a different thread while the first is still playing, this way when the first video ends, the second video can start playing immediatly.
You can play media files on a Windows Phone using the MediaPlayerLauncher , or for a more customized experience, you can use the MediaElement class.
For more Reference Windows Phone Streaming Media Project would be Useful to You and this too How to play or stream a video file for Windows Phone 8.
I am writing a Windows Phone application with ability to play video. I have found a lot of custom video players, but I want to find out, is there a standard video player in Windows Phone and what I need to do for using it?
http://msdn.microsoft.com/en-us/library/ff769551(v=VS.92).aspx
The MediaElement is the standard control for playing video files in WP7 apps.
You can use default media player with the help of MediaElement and MediaPlayerLauncher.
You can play local videos and urls with video.
I hope this link will help you
*http://www.developer.nokia.com/Community/Wiki/Video_Playback_with_MediaElement*
When you stop your music which is playing in the music player, it doesn't really stop it. It just pauses it, as you are still able to see the music controls after you lock the screen. I want to remove the volume controls (rewind,play,forward) buttons which appear on the locked screen using the code behind. This has already been achieved by an existing app on the marketplace Stop the Music!. I have gone through this page, but still I am not able to understand how they are able to do so.
Is there anyway to achieve this??
Nice question, after some trial&error testing I've actually found out, how to remove the Music player from volume controls:
You need to add into your app empty file with .wma extension and set the build action as "Content", for instance "empty.wma" into the app root folder.
To stop the media playback and remove the media player just create dummy Song object and try to play it like this:
Song s = Song.FromUri("empty", new Uri("empty.wma", UriKind.Relative));
MediaPlayer.Play(s);
And that's all, because the file is invalid music file, nothing is playing and even the previous Music player has been removed.
Note I've tested this on Windows Phone 8 device with GDR3 update. Not sure, if it works as well on Windows Phone 7.5.
You don't need to do that now. Windows Phone 7.8 now have the music control as a popup when pressed volumn button on devices.
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.