none
Play .MP3 file in VB.Net RRS feed

  • Question

  • Can any one tell me how can I play a .MP3 file in a VB.Net project.????
    Friday, August 10, 2007 3:31 AM

Answers

  • The simplest method to play MP3 or WAV songs through a VB project is to use the Windows Media Player Control. In fact, you can use this control to play all file formats supported by the Windows Media Player, the default player in your Windows OS. But let's now focus on MP3 and WAV ! Smile

    (See below for alternative methods using <a href="#post2141184">DirectX</a>, or <a href="#post2840118">sndPlaySound, or MMControl</a>)


    You can access this control through Project->Components (or press CTRL+T to open the Components Dialog box). Under the Controls tab, tick the box next to "Windows Media Player".

    Place one instance of this control on your form of the project (I renamed it to mp3 in the attached project). The 4 basic controls you need to play a song is PLAY it, STOP it, PAUSE it, and of course to start with you must OPEN it in the control.

    The Methods used by this control for the above-mentioned operations are:

    1 -> .Play to PLAY a song;
    2 -> .Stop to STOP a song;
    3 -> .Pause to PAUSE a song; and
    4 -> .FileName to OPEN a song in the Media Player control.

    Various other useful Methods supported by this control are as follows:

    (a) .Cancel -> Cancels the Open method before the file completes opening.

    (b) .FastForward -> Scans rapidly forward through the current clip.

    (c) .FastReverse -> Scans rapidly backward through the current clip.

    (d) .GetCodecDescription -> Retrieves the descriptive name of the given codec.

    (e) .GetCurrentEntry -> Retrieves the current clip being played.

    (f) .GetMediaInfoString -> Retrieves show or clip information like that of ID3 tags.

    (g) .Next -> Jumps to the next clip in a playlist.

    (h) .Previous -> Jumps to the previous clip in a playlist.Please note that this is not the full list, these are just the ones which are most useful in this situation.


    There are several Properties available to you, which you can use to determine (or set) features of the player or sound file. These include:

    (a) .AllowScan -> Read/Write Sets or retrieves a value specifying whether scanning is enabled for files that support scanning (fast-forwarding and rewinding).

    (b) .AutoRewind -> Read/Write Sets or retrieves a value specifying whether the Windows Media Player control automatically returns to the clip's starting point after the clip finishes playing or has otherwise stopped.

    (c) .AutoStart -> Read/Write Sets or retrieves a value specifying whether to start playing the clip automatically.

    (d) .Balance -> Read/Write Sets or retrieves a value indicating the stereo balance.

    (e) .Bandwidth -> Read-only Retrieves the bandwidth of the current clip in bits per second.

    (f) .CanSeek -> Read-only Retrieves a value specifying whether the current file has the ability to seek to a specific time.

    (g) .CreationDate -> Read-only Retrieves a value specifying the date and time when the clip was created.

    (h) .CurrentPosition -> Read/Write Sets or retrieves a value representing the clip's current position, in seconds.

    (i) .CurrentState -> Read-only Specifies the playback file's current state: stopped, paused, or running.

    (j) .Duration -> Read-only Retrieves a value indicating the clip's playing time in seconds.

    (k) .Enabled -> Read/Write Sets or retrieves a value specifying whether the control is enabled.

    (l) .FileName -> Read/Write Sets or retrieves a value specifying the name of the clip to play.

    (m) .HasError -> Read-only Retrieves a value specifying whether the control currently has an error.

    (n) .Mute -> Read/Write Sets or retrieves a value indicating the current mute state of the Windows Media Player control.

    (o) .PlayCount -> Read/Write Sets or retrieves a value indicating the number of times a clip plays.

    (p) .PlayState -> Read-only Retrieves a value indicating the state of the Windows Media Player operation.

    (q) .Volume -> Read/Write Sets or retrieves a value specifying the volume, in hundredths of decibels.
    If you still have any queries, please use the following link for more documentation on the Windows Media Player Control: MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemultimedia5/html/_wce50oriwindowsmediaplayercontrol.asp)
    Tuesday, September 4, 2007 11:13 PM

All replies

  • The simplest method to play MP3 or WAV songs through a VB project is to use the Windows Media Player Control. In fact, you can use this control to play all file formats supported by the Windows Media Player, the default player in your Windows OS. But let's now focus on MP3 and WAV ! Smile

    (See below for alternative methods using <a href="#post2141184">DirectX</a>, or <a href="#post2840118">sndPlaySound, or MMControl</a>)


    You can access this control through Project->Components (or press CTRL+T to open the Components Dialog box). Under the Controls tab, tick the box next to "Windows Media Player".

    Place one instance of this control on your form of the project (I renamed it to mp3 in the attached project). The 4 basic controls you need to play a song is PLAY it, STOP it, PAUSE it, and of course to start with you must OPEN it in the control.

    The Methods used by this control for the above-mentioned operations are:

    1 -> .Play to PLAY a song;
    2 -> .Stop to STOP a song;
    3 -> .Pause to PAUSE a song; and
    4 -> .FileName to OPEN a song in the Media Player control.

    Various other useful Methods supported by this control are as follows:

    (a) .Cancel -> Cancels the Open method before the file completes opening.

    (b) .FastForward -> Scans rapidly forward through the current clip.

    (c) .FastReverse -> Scans rapidly backward through the current clip.

    (d) .GetCodecDescription -> Retrieves the descriptive name of the given codec.

    (e) .GetCurrentEntry -> Retrieves the current clip being played.

    (f) .GetMediaInfoString -> Retrieves show or clip information like that of ID3 tags.

    (g) .Next -> Jumps to the next clip in a playlist.

    (h) .Previous -> Jumps to the previous clip in a playlist.Please note that this is not the full list, these are just the ones which are most useful in this situation.


    There are several Properties available to you, which you can use to determine (or set) features of the player or sound file. These include:

    (a) .AllowScan -> Read/Write Sets or retrieves a value specifying whether scanning is enabled for files that support scanning (fast-forwarding and rewinding).

    (b) .AutoRewind -> Read/Write Sets or retrieves a value specifying whether the Windows Media Player control automatically returns to the clip's starting point after the clip finishes playing or has otherwise stopped.

    (c) .AutoStart -> Read/Write Sets or retrieves a value specifying whether to start playing the clip automatically.

    (d) .Balance -> Read/Write Sets or retrieves a value indicating the stereo balance.

    (e) .Bandwidth -> Read-only Retrieves the bandwidth of the current clip in bits per second.

    (f) .CanSeek -> Read-only Retrieves a value specifying whether the current file has the ability to seek to a specific time.

    (g) .CreationDate -> Read-only Retrieves a value specifying the date and time when the clip was created.

    (h) .CurrentPosition -> Read/Write Sets or retrieves a value representing the clip's current position, in seconds.

    (i) .CurrentState -> Read-only Specifies the playback file's current state: stopped, paused, or running.

    (j) .Duration -> Read-only Retrieves a value indicating the clip's playing time in seconds.

    (k) .Enabled -> Read/Write Sets or retrieves a value specifying whether the control is enabled.

    (l) .FileName -> Read/Write Sets or retrieves a value specifying the name of the clip to play.

    (m) .HasError -> Read-only Retrieves a value specifying whether the control currently has an error.

    (n) .Mute -> Read/Write Sets or retrieves a value indicating the current mute state of the Windows Media Player control.

    (o) .PlayCount -> Read/Write Sets or retrieves a value indicating the number of times a clip plays.

    (p) .PlayState -> Read-only Retrieves a value indicating the state of the Windows Media Player operation.

    (q) .Volume -> Read/Write Sets or retrieves a value specifying the volume, in hundredths of decibels.
    If you still have any queries, please use the following link for more documentation on the Windows Media Player Control: MSDN (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemultimedia5/html/_wce50oriwindowsmediaplayercontrol.asp)
    Tuesday, September 4, 2007 11:13 PM
  • Thanks a lot Preetam...
    Sunday, September 9, 2007 4:30 PM
  • 10x a lot for this info..

    grt going dude..
    Wednesday, September 12, 2007 10:52 AM
  • hey...... nice sort of information. thnx a lot

     

    Friday, September 14, 2007 7:58 PM
  • nothing better than watching this on vedio n learning it...  simple solution n nice explanation from this guy

    jus play n enjoy it..



    Video: How-To Series Windows Forms Controls VB - Audio Part II

     

    credits.. msn soapbox..

    Monday, December 3, 2007 2:55 PM
  • Your attached files does not show here again. Please could you attach it again or send it to email
    Sunday, February 20, 2011 2:52 AM