Results 1 to 6 of 6

Thread: Media player problems...

  1. #1

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Media player problems...

    Anyone mind telling me what's wrong in this code?
    VB Code:
    1. REM Play a sound
    2.     Public Function PlaySound(ByVal Filename As String, Optional ByVal optPlayCount As Integer = 1, Optional ByVal optVolume As Integer = 100) As Boolean
    3.         Dim x As New AxWMPLib.AxWindowsMediaPlayer
    4.         Try
    5.             x.URL = Filename
    6.             x.settings.playCount = optPlayCount
    7.             x.settings.volume = optVolume
    8.             x.Ctlcontrols.play()
    9.         Catch ex As Exception
    10.             'An error occured
    11.             Return False
    12.             Exit Function
    13.         End Try
    14.  
    15.         'Sound played successfully
    16.         Return True
    17.     End Function

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Media player problems...

    If you're just playing a short WAV sound then you're better off using the PlaySound API function. If you want to use WMP without an interface, i.e. without adding the control to your form, then I'd suggest not using the ActiveX control but rather an instance of the WMPLib.WindowsMediaPlayer class, which is intended to be used that way. More than that I can't really say as I don't have much experience in that regard.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Media player problems...

    Quote Originally Posted by Ruku
    Anyone mind telling me what's wrong in this code?
    VB Code:
    1. REM Play a sound
    2.     Public Function PlaySound(ByVal Filename As String, Optional ByVal optPlayCount As Integer = 1, Optional ByVal optVolume As Integer = 100) As Boolean
    3.         Dim x As New AxWMPLib.AxWindowsMediaPlayer
    4.         Try
    5.             x.URL = Filename
    6.             x.settings.playCount = optPlayCount
    7.             x.settings.volume = optVolume
    8.             x.Ctlcontrols.play()
    9.         Catch ex As Exception
    10.             'An error occured
    11.             Return False
    12.             Exit Function
    13.         End Try
    14.  
    15.         'Sound played successfully
    16.         Return True
    17.     End Function


    Hi Ruku,

    I think you forgot to declare some functions.
    That is how I play a sound with Playsound, try it:

    VB Code:
    1. Const SND_ASYNC As Integer = &H1
    2.     Const SND_FILENAME As Integer = &H20000
    3.     Const SND_NODEFAULT As Integer = &H2
    4.     Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Integer, ByVal dwFlags As Integer) As Integer
    5.  
    6. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    7.         PlaySound("c:\1.mp3"), 0, SND_NODEFAULT Or SND_ASYNC Or SND_FILENAME)
    8.     End Sub

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  4. #4

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Re: Media player problems...

    Quote Originally Posted by sparrow1
    I think you forgot to declare some functions.
    Not...

    I just wanted to use integrated .net functions instead, but I guess I'll resolve to API...

    bah well, thx guys...

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Media player problems...

    The WMP control is COM anyway so it's not really .NET anway. Note that .NET 2.0 has a SoundPlayer component. Also, you may like to follow the Mentalis.org link in my signature. They have two classes that wrap certan API functions to make playing WAV and other sound files easier. When you get right down to it, that's all the .NET SoundPlayer will do anyway.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member Ruku's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    655

    Re: Media player problems...

    Meh, I guess I'll just resolve to API anyhow...

    Using VB.NET 2005/.NET 2.0, NetBeans IDE 5, Fujitsu Cobol85,
    Website: http://DreamForgery.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width