none
Visual Basic 2010 Express and Windows Media Player

    Question

  • Back in May, I asked how to add Windows Media Player to my VB project.

    I finally was able to drop it on the form.

    Now I'm getting to my project, and am having a problem

    When I call Media Player, I get the followiing message:

    "The file you are attempting to play has an extension of .WMA that does not match the file format.  Playing the file may result in unexpeted behavior"

    If I reply "Yes" to this, nothing seems to happen.

    Here is an abbreviated version of my code:

    In my SingaAlong.Designer I have:

    Me.Menu_Strip.SuspendLayout()                                           
    CType(Me.AxWindowsMediaPlayer1, System.ComponentModel.ISupportInitialize).BeginInit()

    In my Form I have:

    Imports WMPLib

    .

    Private Sub MP3_Play_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles MP3_Play_Button.Click       

        Dim Z As String  

    Z = Song_WMAFileName(Song_Number)
    Z = Trim$(Z)                    

    AxWindowsMediaPlayer1.URL = Z           
    AxWindowsMediaPlayer1.Ctlcontrols.play()

    However, if I use Windows Exployer and double-click on the file, it brings up Windows Media Player and plays the song.       

    Any body have any ideas?                       

    Thursday, July 18, 2013 4:21 PM

Answers

  • Gene,

    It would make life easier if you dragged the components to your form. Even if you want to "create it in code", I'd suggest that you drag it to your form then delete it. Here's why:

    As you can see there, it adds the references for you. Now delete it and create it in code if you want to:

    Option Strict On Option Explicit On Imports System.IO.Path Imports AxWMPLib Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim dt As String = My.Computer.FileSystem.SpecialDirectories.Desktop Dim songPath As String = Combine(dt, "07 Down in the Willow.wma") Dim player As New AxWindowsMediaPlayer player.Dock = DockStyle.Fill Me.Controls.Add(player) player.URL = songPath End Sub End Class



    Please call me Frank :)

    Thursday, July 18, 2013 5:01 PM
  • I've never been successful at trying to manipulte (nor even monitor the events of) the WMP.

    I load a URL and it plays - beyond that, I don't know. Also be aware that if you get it working on your end, if your users have a different version of WMP, theirs may not work.


    Please call me Frank :)

    Wednesday, July 24, 2013 5:48 PM

All replies

  • Gene,

    It would make life easier if you dragged the components to your form. Even if you want to "create it in code", I'd suggest that you drag it to your form then delete it. Here's why:

    As you can see there, it adds the references for you. Now delete it and create it in code if you want to:

    Option Strict On Option Explicit On Imports System.IO.Path Imports AxWMPLib Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load Dim dt As String = My.Computer.FileSystem.SpecialDirectories.Desktop Dim songPath As String = Combine(dt, "07 Down in the Willow.wma") Dim player As New AxWindowsMediaPlayer player.Dock = DockStyle.Fill Me.Controls.Add(player) player.URL = songPath End Sub End Class



    Please call me Frank :)

    Thursday, July 18, 2013 5:01 PM
  • OK, I thought it might be better to do that.

    I'll try it

    Thursday, July 18, 2013 5:48 PM
  • Ok I tried it, and I get the following error messages:

    Abbreviated code:

    In the Form_Load:

    Dim Player As New AxWindowsMediaPlayer

    Player.Dock = DockStyle.Fill         

    Me.Controls.Add(Player)              

    In the Play_Button_Click:

    If MP3_Play_Button.Text = "Stop" Then

                            Player.Ctlcontrols.stop()       

                            MP3_Play_Button.Text = "Play MP3"

                            Exit Sub                        

    End If                              

    ' Try #1 ===>              

    Player.URL = Z             

    Player.Ctlcontrols.Play()  

    ' Try #1 <===              

                               

    ' Try #2 ===>              

    ' Player.URL = Z           

    ' Try #2 <===               

                               

    ' Try #3 ===>              

    ' Player.Ctlcontrols.Play(Z)

    ' Try #3 <===              

    All three tries give me the message “Option Strict On Disallows late binding on this statement:”

    Player.Ctlcontrols.stop()

    And these two:

    Player.URL = Z          

    Player.Ctlcontrols.Play()

    Also, Is the Imports statement:

    Imports WMPLib

    or

    Imports AxWMPLib

    Thanks for the help.

    Gene

    Wednesday, July 24, 2013 4:47 PM
  • I've never been successful at trying to manipulte (nor even monitor the events of) the WMP.

    I load a URL and it plays - beyond that, I don't know. Also be aware that if you get it working on your end, if your users have a different version of WMP, theirs may not work.


    Please call me Frank :)

    Wednesday, July 24, 2013 5:48 PM