Change destination media for Windows Media Player

We use the built-in AxWMPLib.AxWindowsMediaPlayer to play various audio files in our application (C # code). I would like to programmatically change the destination speakers (audio output device). I can not find the code for this. I searched high and low. Nothing tells me how to select and / or change speakers for audio output. However, the standard Windows Media Player in Windows XP can certainly easily switch audio devices through Tools / Options.

(I do not want to change the default sound card, only to change it for this WMP instance)

Can someone show me the light on how to change speakers in C # code?

+4
source share
2 answers

As far as I know, WMP management does not have this feature. You might want to use some third-party media libraries, depending on the type of media you want to use. If you only need to play audio files, you can try the Bass libraries - www.un4seen.com . If you need video capabilities, you may need to use DirectShow. There is a library with samples here . If you want to use WPF as a viewer, there is a large media library called the WPF Media Kit , which is available on CodePlex here .

+2
source

I want to convert the following VB code to C #.

Private Function strFile(ByVal nFile As String) As Object Dim media = AxWindowsMediaPlayer1.newMedia("D:\QueSoft\Media\" & nFile.ToLower & ".mp3") Return media End Function Private Sub PlayAudio() AxWindowsMediaPlayer1.currentPlaylist.clear() Dim arr() As String = Spell(LblNumber.Text).Split(" ") For Each value As String In arr Dim media = strFile(value) AxWindowsMediaPlayer1.currentPlaylist.appendItem(media) Next AxWindowsMediaPlayer1.Ctlcontrols.play() End Sub 

I used the online converter and got the following:

 private object strFile(string nFile) { WMPLib.IWMPMedia media = axWindowsMediaPlayer1.newMedia(@"D:\QueSoft\Media\" +nFile.ToLower()+ ".mp3"); return media; } private void PlayAudio() { WMPLib.IWMPPlaylist AntrianPlaylist = axWindowsMediaPlayer1.playlistCollection.newPlaylist("AntrianPlaylist"); AntrianPlaylist.clear(); string strLP = lblTerbilang.Text; foreach (string value in strLP) { WMPLib.IWMPMedia media = axWindowsMediaPlayer1.newMedia(strFile(value)); axWindowsMediaPlayer1.currentPlaylist.appendItem(media); } axWindowsMediaPlayer1.playlistCollection.importPlaylist(AntrianPlaylist); axWindowsMediaPlayer1.currentPlaylist = AntrianPlaylist; axWindowsMediaPlayer1.Ctlcontrols.play(); } 

This is the error I get:

Error in foreach: cannot convert chart to string Error at strFile (value): cannot convert object to IWMPLib.IWMPMedia

How can i solve this?

-1
source

All Articles