BackgroundAudioPlayer doesn't start playing - c#

Windows Phone 8 app.
We're using AudioStreamingAgent/Mp3MediaStreamSource to play MP3 files which could be cached locally or loaded from web.
When file is downloaded we are still using AudioStreamingAgent /Mp3MediaStreamSource to ensure we will be able to precache next file while playing current.
Yes, we could use just WP8 built-in player for cached files, but we will not be able to precache next file in this case.
Problem:
After several tracks, BackgroundAudioPlayer doesn't start playing anymore.
AudioStreamingAgent.OnBeginStreaming is executed
Сode to create MediaStreamSource is executed
AudioStreamer.SetSource method is executed with new MediaStreamSource instance
PlayStateChanged is fired in background process with PlayState.TrackReady and player.Play() is called in this case.
After all, I see the track is shown in UVC, but it's in state "Paused". Pressing "Play" in UVC calls OnUserAction in background which calls player.Play(). Nothing changes.
Picture of "stuck state"
Sample with problem reproduction, VS 2012 (sample is based on Background Audio Streamer Sample)
Steps to reproduce with sample code:
Install app
Press button "Preload tracks". It copies mp3 files from XAP to IsolatedStorage.
Press "Track 1" button. After track starts playing, press button "Track 2". Then, after track 2 starts playing, press button "Track 3".
Keep doing step 3 until after pressing "Track *" button track doesn't start playing.
Last track selected will be shown as an active track both in UVC and above progress bar on the page (see picture)
Pressing other track buttons in most cases doesn't make any difference.
The problem is reproduced both on device and on emulator, both on WP8 and WP8.1 developer preview.
Update: Running out of memory is not the case. Reproducing the problem using sample code and looking at the backgroundlog.xml file shows that sample uses only 6 Mb out of 20 Mb allowed Last column on this picture is "Memory usage|Max allowed memory usage"

In my experience with this, my suggestion would be to port and start working with WPA8.1 where the limitations with playing background audio go away.
In developing a music player app for WP and trying to cache music while using a mediastreamsource, I finally came to the conclusion that it might not be possible. It seems that you have a set amount of time or some other variable before the OS stomps on any tasks or background type work being done.
I wrote this up for a MS evangelist:
https://drive.google.com/file/d/0By_e5C-QWr9Ka3RmbVBlWVF3R1E/edit?usp=sharing
Here are some other SO's I favored when trying to solve this:
BackgroundAudioPlayer is 'Playing' but not calling GetSampleAsync()
WP7 background audio resources are no longer available
HttpWebRequest from AudioPlayerAgent
AudioPlayerAgent, timer and webservice
WP7 Mp3MediaStreamSource demo not working

Related

Playing videos without lag or black screen in C# winforms

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.

How to navigate to Windows Phone 8 start screen using C#

I have built a very basic sound board app by following video tutorial series on channel 9 [http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners]. Each page in the app displays a list of sound tiles, which on tap plays associated sound. I have extended the app to allow user to tile the individual sound to phone's start screen. Everything works fine upto this point.
Now whenever user taps the sound from start screen, I want app tile to just play the sound, however its navigating into the application at the moment. I have raised similar question on channel 9 and the video series author suggested me that its possible by calling NavigationService.GoBack method on OnNavigatedTo event. I tried that, however I am getting exception with message 'Cannot go back when CanGoBack is false'. Here is the channel 9 thread - http://channel9.msdn.com/Series/Windows-Phone-8-Development-for-Absolute-Beginners/Part-23-Testing-and-Submitting-to-the-Store
Appreciate if someone helps me to resolve the issue.
Entire source code of my app is available on GitHub at https://github.com/PrasadHonrao/WindowsPhone8/tree/master/SoundJabber
Thanks.
To programmatically exit an application, you can call:
Application.Current.Terminate();
Unfortunately, it will work only on Windows Phone 8, this method isn't available on Windows Phone 7.
You can't use navigationService.GoBack when you don't have navigation history.
When you are in your main page and you want to exit your application you can use NavigationService.RemoveBackEntry() for remove navigation history.
If you want play sound for a specifique user.Create Model ou uri sound as parameter.
For information:
when you use Application.Current.Terminate();.You don't pass in your app.cs.
the simplest you can do is Application.Current.Terminate();

WPF media element gets blank and VLC and WMP goes in non responding mode

I have C# windows application in which one can play videos. I have used three options i.e WPF mediaelement, Windows media player activex component and vlc activex component. In my application. In this I plays video using one of the component at a time. And for that I use two instances of that particular component i.e. first video will play in first instance, then second video will play in second instance, then third will play in first and fourth will in second like this it will go on. the play duration is min 5 secs to some hrs. Now,
When I use WPF media element after some hours the form gets blank and application hangs (I have log4net to log and whenever it gets blank it stops logging) but in task manager instaed of showing not responding it shows running. Also, sometimes it takes lots of memeory.
When I use WMP or VLC activex com object after some hrs appliaction goes in non responding mode and task manager shows it correctly. In this there is no memory problem.
After seeing the above results I strated disposing the objects after its turn gets over. So for each video there is a new instance of the above mentioned components. But still I am getting same problem?
I'm working on a similar project to yours where I'm using VLC activex. I experienced the same problems you are describing. To solve this issue, I've added the VLC pluging in a a GroupBox and disabled the GroupBox by setting the Enabled property to false. Let me know if it works for you.

Exocortex(Windows 7 Update) seems to interfere with MediaElement

I have a working program that could load and play a video file. It has a canvas over the video on which an interrupt draws events loaded from a separate text or csv file. It was all working marvelously and I have been using it for weeks, but I wanted to add fft and video analysis functionality. I added Exocortex to the project and now loaded videos don't play and loaded events don't display on the canvas.
I can't think of why this would have any effect, and it's the only change that's been made. The rest of the program appears to work normally. Does Exocortex have anything about it that might interfere with MediaElements or Canvases?
EDIT: Further investigation suggests the problem is not with Exocortex, but with the mediaelement and a recent Windows 7 Update. The solution is still evading me.
A reformatting my computer with a new install of windows 7 has fixed the problem. In other words, I have absolutely no idea what was broken and what wasn't working. Windows Media player was experiencing the same problem.

How to remove volume controls on lock screen in WP7?

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.

Categories

Resources