How can I stop background audio played by other apps? - windows-phone-7

I have an app for WP7, using BackgroundAudioPlayer as we need to play in the background. The problem is, when there's already an app playing audio in the background, I can't get my AudioPlaybackAgent work, the previous music just keep playing.
The document introduced this way,
BackgroundAudioPlayer.Instance.Close();
by which I can only close the audio that is played by myself or Zune, but it doesn't work when the audio is played by other apps.
So is there a way to close all the playing audio?

OK I fixed it.
What I did to get it play is like this, first I set a track to the player:
BackgroundAudioPlayer.Instance.Track = ...;
Then an OnPlayStateChanged event will fire in the background agent, where I call the BackgroundAudioPlayer.Instance.Play() method. This seems to work great.
But if the background player is already being used by another app, the PlayState won't change to TrackReady when I set the track, and consequently the event won't fire.
To fix this, I simply call the .Play() method in the main UI thread, right after setting the track. And it works.

Related

How to load a file in IWMPPlayer without playing it?

I've got a project that uses IWMPPlayer4, the ActiveX interface to Windows Media Player. Downloading and playing a video from the Internet is easy: just call put_URL, and it connects to the video and begins to play it.
But what if I want to tell it to load up a video from a certain URL but not begin to play it yet? It's not clear from the documentation I've seen how I would do that, but I figure there has to be a way to accomplish it. Does anyone know how?
I tried calling get_controls and then either the Pause or Stop methods on the resulting IWMPControls interface immediately after calling put_URL, but both caused the same problem: no media actually loaded, and clicking the Play button on-screen plays nothing.
It's been a long time since I've worked with WMP API's, but I think you want this:
IWMPSettings::put_autoStart
From the MSDN link above:
You should set put_autoStart to FALSE immediately before you set
IWMPCore::put_URL, IWMPCore::put_currentPlaylist, or
IWMPCore::put_currentMedia in skins and remoted Player controls if you
wish to ensure that the media item does not start playing immediately.
Also, unless you set put_autostart to TRUE immediately before
specifying a media item, you should not rely on this setting as a
substitute for using the IWMPControls::play method.

Windows phone music player

I am developing a music player using X N A in windows phone.
Here I am using a slider to automatic synchronizing of songs.
Problem is how can i seek song in slider .I am also using timer.
MediaPlayer.PlayPosition=TimeSpan.FromMilliseconds(slider1.Value);
I have tried mediaPlayer.PlayPosition propety in slider mouse left button event but it is saying play position property is read only.So
please help.
This seems practically impossible to do..
Here's the UserVoice request, asking just this.
http://wpdev.uservoice.com/forums/110705-dev-platform/suggestions/2411252-mediaplayer-playposition-should-be-able-to-be-set
There are some other tricks to accomplish this, as explained in this question. (Though it would be an overkill by the look of it.)
XNA MediaPlayer fastforward/rewind

How to identify a window playing a video in a browser

I wish to understand how one can programmatically identify if a window is playing video content?
I used spy++ to identify particular attributes for windows playing video but I did not find any particular attributes associated with window playing video.
I have handles to all windows on screen and want to find which ones are playing video ? Could you please throw some light on how can one do this and are there any special properties associated with a window playing video?
I found similar article :
can we get window handle of the window which is playing video?
But I don't want to minimize application , I know user is using browser(ie,firefix,chrome) to watch video (from youtube,hulu)and window is visible on screen.
You can if you have execution privileges over the environment the Flash Player is executed in. You can listen for the playing event thrown by the Flash Player.
Listen for my Flash event in Javascript

IOS Music Control in Background

I am trying to find the solution to have the control of play/pause when my app is playing the own music in Background. I am using AVAudioPlayer and didnĀ“t find the way to implement this controls. When the app is "close" the music play perfectly but I have to open the app again to pause or change music when needed.
Any solution ?
If you're running iOS 4 you can try putting the app in the background whilst playing music, and then pressing the home button twice for the 'multitasking' bar.
Swipe the bar to the right, which shows you the normal playback controls for Music, YouTube, etc.
If you use the AVAudioPlayer I'm quite sure you can use those same controls to control your app's playback of media.
Bryan
*EDIT does using the remote on the iPhone headphones work?

WP7 MdeiaPlayer Event for video finished playing

I am using MediaPlayerLauncher for playing video. How do we get some notification when the MediaPlayerLauncher is opened() and the video is finished it's playback or the MediaPlayerLauncher is closed.
You can't explicit know if it's from a video or another navigation, but the OnNavigatedTo event will tell you when the user returns to your page.
By using the built in MediaPlayer you are giving up a lot of control to playback. If you really must* know when a video has finished playing you should use the MediaElement and detect the MediaEnded event.
* The end of a movie is typically a grey area. Does it include any ending credits? Is it when the user has watched "enough"? Is a certain percentage through the video sufficient ?

Resources