Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello again!!!

How can I use windows media player to play music files(mp3 etc.) and videos with an VB NET application. First I add a reference of Windows media player to my application (Project->add->reference->COM->Windows media player), and after that????

Thanks a lot!!

Posted

Set up an OpenDialogBox Control to open files and set them up

'Once the box closes:
WindowsMediaPlayer1.URL = MyOpenDialogBox.FileName
WindowMediaPlayer1.Play

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
Posted

It doesn't work...

 

 

Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
       Dim windowsmediaplayer As New MediaPlayer.MediaPlayer()
       OpenFileDialog1.DefaultExt = ".mp3"
       OpenFileDialog1.AddExtension = True
       OpenFileDialog1.Filter = "mp3 files|*.mp3"
       If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
           windowsmediaplayer.Open(OpenFileDialog1.FileName)
           windowsmediaplayer.Play()        
       End If
   End Sub

 

ps:I have added a reference (media player)

 

 

error message:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in WindowsApplication11.exe

 

Additional information: Exception from HRESULT: 0x800A0005 (CTL_E_ILLEGALFUNCTIONCALL).

 

 

 

please help with details!!!!!!!, tyvm

  • 2 years later...
Posted
I have the same problem as Geonab above. Is there a way around it?

 

Cheers

 

Firebeard

 

Install the managed directX runtimes and use Microsoft.DirectX.AudioVideoPlayback.Audio instead of media player.

Posted

How?

 

Thanks for the tip Wraith. I've tried adding references to the DirectX runtimes, but I can't find them! Do they get installed as standard, or should I be downloading them?

Posted

Fixed that bit - now another question

 

Hello again

 

Right, I got details on how to set up the MediaPlayer control as part of a form from the Microsoft website, so I can now play a file successfully. Now I want to play another straight afterwards (like on an album).

 

The problem is, the code I run to play the next song is triggered by a change of playstate (when media ends) and it doesn't work. I can step through and see that it's running properly and check that the MediaPlayer controls are being processed correctly; they just don't do anything.

 

My code is as follows:

 

Private Sub PlaySong()

Dim FileName As String

 

FileName = TrackDetails(CurrentTrack).Item("FileName")

 

MediaPlayer1.Ctlcontrols.stop()

MediaPlayer1.URL = FileName

MediaPlayer1.Ctlcontrols.play()

 

End Sub

 

I'm running this when I click on a track and when a track finishes. It works for the MouseDown event but not for when the play state has changed.

 

Any ideas welcome!

 

Firebeard

Posted
Hello again

 

Right, I got details on how to set up the MediaPlayer control as part of a form from the Microsoft website, so I can now play a file successfully. Now I want to play another straight afterwards (like on an album).

 

 

I managed to do it like this:

Add a timer with interval of 10 and then add the code below.

PlayNext() would be your function to play the next song.

And Player would be the MediaPlayer10 object.

 

 

Public EndOfStream As Boolean

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       EndOfStream = True

       'Start Timer
       Timer1.Enabled = True

   End Sub

   Private Sub Player_PlayStateChange(ByVal sender As System.Object, ByVal e As AxWMPLib._WMPOCXEvents_PlayStateChangeEvent) Handles Player.PlayStateChange

       If e.newState = 8 Then EndOfStream = True 

   End Sub

   Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

       'File EndOfStream
       If EndOfStream = True Then
           EndOfStream = False
           PlayNext()
       End If

   End Sub

  • 1 month later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...