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.
Related
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
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();
I have been struggling with an issue with my media player windows phone (7) application. The problem is that I can't seem to implement playlists.
What I want to do is play songs from the media library. This article seems pointless.
I've tried getting into the SongCollection class and figure out how to create more of these things. It appears to be impossible (no constructor, can't cast it, can't inherit it).
After that I tried getting an object on the process running the background audio agent that existed in my app (until I discovered it was redundant), and feed the media player one song at a time.
Problem is, I don't know when the media player stopped playing. It works ok as long as my app is in the foreground, but when it is not, everything stops working, only the media player keeps going.
Is there a way I haven't figured out? In the article above they suggest there is a link between the Zune Media Queue, which I presume is the MediaPlayer.Queue property, and various things I can implement, but I just can't figure a way to make it go.
You should give up since building your own media player is an impossible mission (been there, done that). You cannot create playlists or edit any information, you cannot replace default event handlers for on-screen music controls, you don't get events for music change in your application unless it is currently running.
Basically, it is really limited in what you can do right now and the situation isn't much better with WP8.
I hope that it will be less read-only by the time we get Windows Phone 9.
Take a look at the UWP samples from Microsoft:
https://github.com/Microsoft/Windows-universal-samples
The sample contains play/pause/playlists explanation.
This was already possible in Windows phone 7.5/8/8.1
I'm building a small media selector application. All medias of a given directory are loaded one by one based on left/right key navigation and displayed in Windows Media Player control that is on a windows form (C#).
I works well with videos, audio, but less with still images.
The image is displayed correctly, but after a few seconds it disapears. I looks like the media player is "playing" it for a few second, then "stop" it.
How can I make the Windows Media Player control to stay on the image until I load another media in the player ?
Here is how I solved the problem. In case the loaded media is an image, I pause the WMPC. It works, but I don't like it.
ThreadStart start = new ThreadStart(delegate() {
Thread.Sleep(2000);
this.axWindowsMediaPlayer1.Ctlcontrols.pause();
});
start.BeginInvoke(null, null);
I am developing an application in C# that has a form with Windows Media Player embedded inside. There are several links to some online content in my app. and I want user to change the content from one to another with a button click. Since WMP spent some time while buffering for the next content, I want to continue playing the current content. There is an event called "Buffering" in AXWindowsMediaPlayer class that signals when media player finishes buffering the content. But I could not achieve this with a single AXWindowsMediaPlayer object. Whatever I did, I could not continue to play the first content while buffering the second. :(
Any ideas?
Thanks in advance.
I suggest two instances of the Player control that you swap out as needed.
Alternatively, if the connection is fast enough cache each item on the local system and play from there.