locked
AxWindowsMediaPlayer from resources RRS feed

  • Question

  • Hi.

    How i can play a video or an MP3 in a AxWindowsmediaPlayer control from MY.Resources? in VISUAL BASIC 2012.

    Please i really need help.

    Thanx!

    Friday, August 16, 2013 12:27 AM

Answers

  • Hi Paul,

    According to your description, I understood you want to play a video or an MP3 in an AxWindowsMediaPlayer control from My.Resources.

    I created a sample to implement this function. The detailed steps below,

    1. Project Properties -> Resources tab

    When you add existing files, a Resources folder containing the added files will created under project directory. Thus, you can reference to your mp3 file using relative path instead of My.Resources.file

    2. You can use Windows Media Player control to play mp3 files.

    Right-click the Toolbox -> Choose item -> COM Components -> add “Windows Media Player” component (which references to C:\Windows\System32\wmp.dll)

    Then you will see “Windows Media Player” control on Toolbox, drag & drop it to Form1, AxWindowsMediaPlayer1 object will be created.

    Here is VB.NET code snippet below:

    Public Class Form1
    
        Dim ResourceFilePath As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            ' Determine the Resource File Path
    
            If System.Diagnostics.Debugger.IsAttached() Then
    
                'Debugging mode
    
                ResourceFilePath = System.IO.Path.GetFullPath(Application.StartupPath & "\..\..\resources\")
    
            Else
    
                'Published mode
    
                ResourceFilePath = Application.StartupPath & "\resources\"
    
            End If
    
            ' Specify the mp3 file
    
            AxWindowsMediaPlayer1.URL = ResourceFilePath & "\Today.mp3"
    
            ' Media Player automatically plays file by default
    
        End Sub
    
    End Class
    

    Here are some useful references maybe help you to understand this issue.

    #How to: Retrieve Audio Resources in Visual Basic

    http://msdn.microsoft.com/en-us/library/vstudio/3e54ke41(v=vs.100).aspx

    #How to add or remove references

    http://msdn.microsoft.com/en-us/library/vstudio/3bka19x4(v=vs.100).aspx

    If you need future assistance, please do not hesitate to tell me.

    Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, August 19, 2013 2:18 AM
  • Imports WMPLib ' Add reference in Project tab, Add reference, Com, Windows Media Player
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim appPath As String = Application.StartupPath & "\Pegasus.wmv"
            My.Computer.FileSystem.WriteAllBytes(appPath, My.Resources.Pegasus, False)
            Dim wmp As New WindowsMediaPlayer()
            wmp.openPlayer(Application.StartupPath & "\Pegasus.wmv")
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As EventArgs) Handles Me.FormClosing
            Try
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Pegasus.wmv")
            Catch ex As Exception
            End Try
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Monday, August 19, 2013 6:49 AM

All replies

  • Hi Paul,

    According to your description, I understood you want to play a video or an MP3 in an AxWindowsMediaPlayer control from My.Resources.

    I created a sample to implement this function. The detailed steps below,

    1. Project Properties -> Resources tab

    When you add existing files, a Resources folder containing the added files will created under project directory. Thus, you can reference to your mp3 file using relative path instead of My.Resources.file

    2. You can use Windows Media Player control to play mp3 files.

    Right-click the Toolbox -> Choose item -> COM Components -> add “Windows Media Player” component (which references to C:\Windows\System32\wmp.dll)

    Then you will see “Windows Media Player” control on Toolbox, drag & drop it to Form1, AxWindowsMediaPlayer1 object will be created.

    Here is VB.NET code snippet below:

    Public Class Form1
    
        Dim ResourceFilePath As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            ' Determine the Resource File Path
    
            If System.Diagnostics.Debugger.IsAttached() Then
    
                'Debugging mode
    
                ResourceFilePath = System.IO.Path.GetFullPath(Application.StartupPath & "\..\..\resources\")
    
            Else
    
                'Published mode
    
                ResourceFilePath = Application.StartupPath & "\resources\"
    
            End If
    
            ' Specify the mp3 file
    
            AxWindowsMediaPlayer1.URL = ResourceFilePath & "\Today.mp3"
    
            ' Media Player automatically plays file by default
    
        End Sub
    
    End Class
    

    Here are some useful references maybe help you to understand this issue.

    #How to: Retrieve Audio Resources in Visual Basic

    http://msdn.microsoft.com/en-us/library/vstudio/3e54ke41(v=vs.100).aspx

    #How to add or remove references

    http://msdn.microsoft.com/en-us/library/vstudio/3bka19x4(v=vs.100).aspx

    If you need future assistance, please do not hesitate to tell me.

    Regards,


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, August 19, 2013 2:18 AM
  • Hi.

    How i can play a video or an MP3 in a AxWindowsmediaPlayer control from MY.Resources? in VISUAL BASIC 2012.

    Please i really need help.

    Thanx!

    Write it to a file first then play it from there. Then on Form Closing delete the file. Also I always use a try catch in the FormClosing event in case it errors so the Form will still close.

    Imports WMPLib ' Add reference in Project tab, Add reference, Com, Windows Media Player
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim appPath As String = Application.StartupPath & "\MiamiVice.mp3"
            'save the embedded app binary to the file path
            My.Computer.FileSystem.WriteAllBytes(appPath, My.Resources.MiamiVice, False)
            Dim wmp As New WindowsMediaPlayer()
            wmp.URL = Application.StartupPath & "\MiamiVice.mp3"
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As EventArgs) Handles Me.FormClosing
            Try
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\MiamiVice.mp3")
            Catch ex As Exception
            End Try
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, August 19, 2013 6:38 AM
  • Imports WMPLib ' Add reference in Project tab, Add reference, Com, Windows Media Player
    
    Public Class Form1
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim appPath As String = Application.StartupPath & "\Pegasus.wmv"
            My.Computer.FileSystem.WriteAllBytes(appPath, My.Resources.Pegasus, False)
            Dim wmp As New WindowsMediaPlayer()
            wmp.openPlayer(Application.StartupPath & "\Pegasus.wmv")
        End Sub
    
        Private Sub Form1_FormClosing(sender As Object, e As EventArgs) Handles Me.FormClosing
            Try
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Pegasus.wmv")
            Catch ex As Exception
            End Try
        End Sub
    
    End Class


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.


    Monday, August 19, 2013 6:49 AM