Implementing playlists with songs from phone storage [windows phone] - c#

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

Related

MediaPlayer vs BackgroundAudioPlayer

I'm developing an Windows Phone application, that plays/streams music in background.
To accomplish that, I tried to use both Microsoft.Phone.BackgroundAudio.BackgroundAudioPlayer and Microsoft.Xna.Framework.Media.MediaPlayer classes.
In both cases everything worked just fine, so I was wondering, what are advantages/disadvantages of these methods, because now I can't decide which one is better.
The only thing that I don't like in BackgroundAudioPlayer, is that I need to create separate project for audio agent, and worry about transferring track info via IsolatedStorage. But since I've done that already. It's not a problem.
So are there any other differences between those two classes?
It depends on your program. If you want to play your background music only while using your program, you should use MediaPlayer. Otherwise you have to take care of the BackgroundAudioPlayer in any situation. Also this will annoy users, who also want to listen to their own music while using your application.
Otherwise, if your background music is the main purpose of the program, the user would like to start your music and switch to other programs. Then it keeps playing and you can control the music in the volume bar. That's why you have to create a background task for BackgroundAudioPlayer. The main application will stop in both ways when switching to other programs.
In short: game background music should never play after leaving the game (use MediaPlayer) - but I never want to watch my music player counting the time, while listening to my music library (use BackgroundAudioPlayer).
I believe MediaPlayer requires the application to be in the foreground. BackgroundAudioPlayer will let the user start a track, exit your application, and the music will continue to play and the agent can respond to the UVC.
Make sure you use a Mutex when you communicate between the foreground app and the background audio agent.

How do I control background music from app?

I have a c#/xaml app. I'd like to play instruction sounds, but if the user is playing background music, I'd like to mute it, or lower the volume temporarily while the sounds are being played.
Currently, I'm using xaudio2 to play my audio in C++, and using some delegates to make calls into C# where I'm using the MediaPlayer class from the xna framework to mute the background media.
However, after pausing the music, when I go to play my instruction through xaudio2, I get System.InvalidOperationException exception from the xna framework. If I comment out the line for playing the sound, there is no exception.
I suppose it's worth noting that this is not happening on the UI thread...
Am I going about this the right way? I can't find any links to information on how to accomplish this - I'm grasping at straws.
It turns out I wasn't calling FrameworkDispatcher.Update() before I called MediaPlayer.Pause(). But this is possible to do if your app requires it.

How to listen to windows events in C#?

I'm developing an lyrics related application and I need to listen to Windows Media Player Events.
I watched windows events in "Accessible event watcher" and I found out that there's some events that WMP sends whenever it's state or current position changes.
I searched and found this article on MSDN a How to set a Windows hook in Visual C# .NET but I couldn't make it work.
How can I listen to that events from my C# application or any suggestions on using other methods to get current song and WMP playing status?\
Thank You
This article describes how to get the events using the AxWindowsMediaPlayer which is the underlying root of the windows media player system. You will see that the various state change events can be picked up normally.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562388(v=vs.85).aspx
You should be able to get a running instance from the windows ROT (Running objects table)?
http://www.darinhiggins.com/the-running-instance-of-windows-media-player/
Edit:
This is another way...
http://www.darinhiggins.com/gaining-access-to-a-running-instance-of-windows-media-player-in-vb-net/
Does this help you? http://forums.msdn.microsoft.com/en-US/clr/thread/dbd43d7e-f3a6-4087-be06-df17e76b635d . There's also this post here Getting windows media player currently playing song that may answer your questions.

Retrieving currently playing song from Windows Media Player (C#)

I realize there is a similar question to this, but it really has no information in it. I want to retrieve the currently playing song title (similar to MSN Messenger) within a C# app. The Windows Media Player I want to control is EXTERNAL- that is, it is running on the computer, not within the app. Anyway to do this?
I think I may have found a way around my problem- a simple solution is to install a plugin that tells you the current playing song and writes it to a file and you can read it through your program.

How to interact with Windows Media Player in C#

I am looking for a way to interact with a standalone full version of Windows Media Player.
Mostly I need to know the Path of the currently played track.
The iTunes SDK makes this really easy but unfortunately there really isn't any way to do it with Windows Media Player, at least not in .Net(C#) without any heavy use of pinvoke, which I am not really comfortable with.
Thanks
Just to clearify: I don't want to embedded a new instance of Windows Media Player in my app, but instead control/read the "real" full version of Windows Media Player, started seperatly by the user
Just add a reference to wmp.dll (\windows\system32\wmp.dll)
using WMPLib;
And then you can instantiate a media player
var Player = new WindowsMediaPlayer();
// Load a playlist or file and then get the title
var title = Player.controls.currentItem.name;
See Creating the Windows Media Player Control Programmatically for more information
For remoting the Windows Media Player, you can use the IWMPRemoteMediaServices interface to control the stand alone Windows Media Player. And you should be able to read all the informations you want like title or filename from your WMP player object. Unfortunately there is no C# smaple code in the SDK included. You can get the files from here: http://d.hatena.ne.jp/punidama/20080227 Look for the file WmpRemote.zip
Originally it's from here: http://blogs.msdn.com/ericgu/archive/2005/06/22/431783.aspx
Then you have to cast to the WindowsMediaPlayer object:
RemotedWindowsMediaPlayer rm = new RemotedWindowsMediaPlayer();
WMPLib.WindowsMediaPlayer myPlayer = this.GetOcx() as WMPLib.WindowsMediaPlayer;
and there you go..
I had this https://social.msdn.microsoft.com/Forums/vstudio/en-US/dbd43d7e-f3a6-4087-be06-df17e76b635d/windows-media-player-remoting-in-c?forum=clr in my bookmarks but have NOT tested it in anyway. Just a pointer in the right direction. It's nothing official and will require a bit of digging, but you should get a fairly simple wrapper (which will still use PInvoke under the hood - but you won't see it) around Windows Media Player.
Hope that helps.
Oh, I misunderstood. I thought you were talking about controlling the currently running Windows Media Player instance. If you are hosting Windows Media Player yourself then WMPLib is certainly the better solution.
The best info I have seen on interacting with Windows Media Player is this article written by Stephen Toub.
He lists a whole load of different ways to play dvr-ms files (doesn't really matter what format they are for this though). The bit that is possibly of interest to you is about using a Media Player ActiveX Control, which you can add to the visual Studio toolbox by right-clicking and adding the Windows Media Player ActiveX COM Control. You can then embed the player into your app, and access various properties of Media Player, like the url:
WMPplayer.URL = stringPathToFile;
This solution is possibly not what you want because it's starting a new instance of Media Player (as far as I know), however it might point you in the right direction.

Categories

Resources