Been trying this for a while now.
All solutions I've seen on the net don't seem to work, specially the really simple way to do it.
WMPLib.WindowsMediaPlayer c = new WMPLib.WindowsMediaPlayer();
IWMPMedia i = (IWMPMedia)c.currentMedia;
c.currentMedia is always null.
It seems that new WMPLib.WindowsMediaPlayer(); is always creating a new instance of the Windows Media Player.
First I thought it was the fact that I was running visual studio as Administrator, but changing that did not help.
Seems I somehow have to connect to the running instance of wmplayer.exe but have unable to find a way to do that.
Btw. What I need is a full file url for the current playing song (or fullurl if streaming, but that's the least of my concerns now.)
Your question answered here.
A pretty straight way:
Get a WMP9 plugin here that will put your current song name on the
titlebar of the WMP window, and use
FindWindow P/Invoke to get the window
and get the song name. It shoud work,
though a little tricky.
Check here for more details.
Windows Media Player 9 Series Blogging Plug-in
A much more complex way:
Since your application and the WMP will be different processes, your
scenario requires some kind of
inter-process-communication (IPC). And
.NET offers Remoting for this purpose.
Below are some useful information:
How to interact with Windows Media Player in C#
Windows Media Player Remoting in C#
from SamAgain
Related
I know it is somehow possible to implement a windows media player in a form with Visual C#.
The info for that is here: How to add the libraries and here How to code it.
But my project is in Visual C++ and I'm having a hard time finding how to do the same. It is a windows store application based on an example from a Hearth Rate Bluetooth monitor.
My goal is to play a video while the data acquisition occurs.
The answer is Windows Store App can't handle ActiveX controls. At least in a straightforward way.
The solution was to implement a MediaElement from the Toolbox into the XAML page. That element is easy to use with mediaElement.Play() and mediaElement.SetSource()
So, I am looking to make a media player that is cross-platform (windows 10 + windows 10 mobile, XBOne, iOS, OSX, and Android), using C# (by far my most proficient language). I need it to remain playing in the background when the user is doing other things (for all but the XBOne). Ideally, I would like to use a cross-platform framework such as Unity, but if that's not possible, I need to know what steps I must take to make my app persist on each platform.
OSX/Windows 10 are easy, but I haven't been able to find absolutely any good information for Android/iOS especially. How does one keep a media player app going in the background on these? I see posts saying a media player that persists is doable, but they never say how.
Lately, I've been trying to setup a media center PC. I've played around with all the common media center applications like XBMC, Plex, Boxee, and WMC. But all of them have one issue or another. So I was thinking about writing my own application from scratch.
My problem is I have no experience with developing software that plays media such as videos or music. I'm also not interested in spending a huge amount of time trying to figure this out, considering all the different file formats and codecs out there. I'm really more interested in developing the database and library interface for my application and reusing someone else's control or code for actually playing the media.
One option I was thinking was to just control an existing media player externally. So for example you may browse for a video to play in my application, and then when you hit play it would fire up VideoLAN or some other popular video player.
However, I was wondering if there was an easy way to play video inside a .NET application. I'm looking for something that is capable of playing a wide variety of formats such as MKV files, and DVD ISOs. I'm more experience with WinForms, but was also thinking about using this project as an opportunity to learn WPF.
i've spent many years looking at playing video under wpf.
The short answer
There is no easy way to guarantee to be able to play a variety of formats under wpf ( mkv,dvd etc etc ) or under windows for that matter.
the long answer
If you are looking just to run this at home and not release it, install all the codecs you need and most of the formats will run via mediaelement in wpf.
Getting all the codecs to cooperate can sometimes be frustrating.
Now moving into slightly harder territory.
if you want to play DVD then you need to replace mediaelement with wpfmediakit
http://wpfmediakit.codeplex.com/
wpfmediakit gives a base library to get access to the low level directshow functionality.
There is already a code base for playing DVDs based on wpfmediakit.
Now moving onto the very hard territory.
if you want to distribute your application and have users be able to "just watch" most/all media formats means you need to be able to completely control their codecs, which generally means distributing the codecs with your package and building the directshow filter graph in code rather than let windows build it.
The easiest way is to use the existing .Net hooks to Microsoft's standard MediaPlayer:
http://msdn.microsoft.com/en-us/library/system.windows.media.mediaplayer.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562851%28v=vs.85%29.aspx
was trying myself a while ago for something to play media in winforms, and found out there is vlc wrappers for .Net, dunno how good they are as i gave up, but you can try
here is one them:
http://vlcdotnet.codeplex.com/
Thanks for all the great answers. But just found out that VLC can actually be controlled through HTTP. So I think I'm just going to use that to point an instance of VLC running with the HTTP interface at whatever file I want to play.
Is there a way to rewind/fast forward (or at least start playing at a certain position of a track) a media that is being played (using XNA.Framework.Media.MediaPlayer static instance) from a Media Library integrated application on Windows Phone Mango?
BTW: I have created a feature request on wpdev user voice community, so if you are in need of the similar functionality, go ahead and make a vote: http://wpdev.uservoice.com/forums/110705-app-platform/suggestions/2459380-allow-setting-a-playback-start-position-within-the
In XNA 4.0 there is no real way of doing this using MediaPlayer unless there are undocumented hacks to get it to. But definitely there are no documented ways of doing this with the MediaPlayer class.
i'm trying to control the VLC Media Player from C#. I tried getting a handle on the window with the FindWindow() command from .Net but as i found out the name of the window changes every time a file is played. The biggest problem i have is sending wm_commands to vlc..This approach worked with Winamp and Windows Media Player but with VLC it appears that it won't work.
I read that VLC can be controlled from a browser but i don't whant that...i've seen in it's settings that it has some hot keys that can be called..but they can be changed and if i call them from my code somehow...and the user changes them..bummer...
i'm a little bit stuck..any help would be fantastic...
Sorin
I have some code that is able to control it using sockets on the RC interface. This worked to a degree but has a lot of quirks. go to full screen seems to do nothing for a few seconds after play is invoked. Overall it sort of works.
The other options are:
Write a DirectDraw filter (very hard) but once this is done VLC can be used instead of or in conjunction with FFMPEG. Existing code that drives media player could use vlc.
Write an interop wrapper for libvlc, recently the VLC team split out libvlccore from libvlc so to the best of my knowledge all the interop is out of date. Once you write a wrapper you could embed vlc in a windows app. (if you need to support x64 you need to compile these libs under x64.
Look through the VLC code and find out if there is a way to send these windows messages.
EDIT This appears to have come out this week.
As Eoin mentioned, libvlc can be used to interact with VLC. As a C# user, you may want to try the .NET bindings offered by the libvlc-sharp project.
Edit: Seems like this project has not been maintained for years. I will leave the link anyway, in case you wish to take a look at it and maybe put some of its source to use.
Have you looked at libvlc
You might be able to wrap that up in a library and interact with VLC through that.
If what you are trying to do is control a previously running executable, check out the Process class to enumerate through all the current processes or do it by name. Check the executable to match vlc.exe. You can then get a handle to the main window and do some P/Invoke to send messages as you are doing with your other executables. This is obviously riddled with potential problems such as if the there are changes to the keyboard shotcuts.
How use libvlc in C++ http://unick-soft.ru/art/files/libvlcProject.zip
I think, use libvlc in C# very similar.
There's also the rc interface and even a telnet one: http://wiki.videolan.org/Console
However, I'd prefer libvlc if possible.