Solved

Playing mp3 files

Posted on 2001-09-03
9
391 Views
Last Modified: 2012-05-04
How can I play mp3 files with MCI control or with any other control in Visual Basic
0
Comment
Question by:sofiansafy
9 Comments
 
LVL 6

Expert Comment

by:JonFish85
ID: 6451247
with the MCI control, I believe you can use this:

MCI.FileName = "C:\myfile.mp3"
MCI.Command = "OPEN"
MCI.Command = "PLAY"

hope this helps!
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 6451258
I have OCX that plays mp3 files, but can't remember where from I downloaded it. If you want, I can send it to you.
0
 

Author Comment

by:sofiansafy
ID: 6451338
jonfish:
I think MCI did not support mp3

Julian k , I will be very glad if you can send it to me and tell me how can I use it.
0
 

Author Comment

by:sofiansafy
ID: 6451360
jonfish:
I think MCI did not support mp3

Julian k , I will be very glad if you can send it to me and tell me how can I use it.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 20

Expert Comment

by:hes
ID: 6451390
0
 

Accepted Solution

by:
master01 earned 50 total points
ID: 6451703
add the Windows Media Player Ocx in the components.  That is how i use mine; i just hide the media player ocx from site and use command buttons to trigger the pause and stop and play

i.e. mediaplayer1.play  mediaplayer1.pause  mediaplayer1.stop

you can set the file by the properties tab of the control or via mediaplayer1.filename=""
0
 
LVL 5

Expert Comment

by:Julian_K
ID: 6451856
Hi again. I would send it to yoy, if only I knew your e-mail...
0
 

Expert Comment

by:ardman090401
ID: 6452703
In order to use Media Player to play MP3 files in Visual Basic, you'll need version 5.2 or later (the Microsoft Web site www.microsoft.com/windows/windowsmedia/en/download/default.asp contains version 6.4 and 7.0). You add the Media Player OCX to a project just like any ordinary OCX component.


Gathering MP3 tag information


Option Explicit
Dim GenresTypes
Dim Min As Integer
Dim Sec As Integer

Dim FileName As String
Dim FileOpen As Boolean
Dim CurrentTag As TagInfo

Private Type TagInfo
      Tag As String * 3
      Songname As String * 30
      artist As String * 30
      album As String * 30
      year As String * 4
      comment As String * 30
      genre As String * 1
End Type

Private Sub File1_Click()
Dim temp As String
On Error Resume Next
EraseTXTBoxes

If Right(Dir1.Path, 1) = "" Then
      FileName = Dir1.Path & File1.FileName
Else
      FileName = Dir1.Path & "" & File1.FileName
End If
   
Open FileName For Binary As #1
With CurrentTag
      Get #1, FileLen(FileName) - 127, .Tag
      If Not .Tag = "TAG" Then
            lblMsg.Caption = "No tag"
            Close #1
            Exit Sub
      End If
      Get #1, , .Songname
      Get #1, , .artist
      Get #1, , .album
      Get #1, , .year
      Get #1, , .comment
      Get #1, , .genre
      Close #1

      txtTitle = RTrim(.Songname)
      txtArtist = RTrim(.artist)
      txtAlbum = RTrim(.album)
      txtYear = RTrim(.year)
      txtComment = RTrim(.comment)
      
      Temp = RTrim(.genre)
      txtGenreCode = Asc(Temp)
      Combo1.ListIndex = CInt(txtGenreCode) - 1
End With
End SubPrivate Sub Dir1_change()
File1.FileName = Dir1.Path
End Sub

Writing the tag information


Private Sub cmdWriteTag_Click()
If FileOpen Then
      MsgBox "You can't save to an open file", _
            vbCritical, "MP3 Tag Save Error"
      Exit Sub
End If
   
If Right(Dir1.Path, 1) = "" Then
      FileName = Dir1.Path & File1.FileName
Else
      FileName = Dir1.Path & "" & File1.FileName
End If

With CurrentTag
      .Tag = "TAG"
      .Songname = txtTitle
      .artist = txtArtist
      .album = txtAlbum
      .year = txtYear
      .comment = txtComment
      .genre = Chr(Combo1.ListIndex + 1)
   
      Open FileName For Binary Access Write As #1
            Seek #1, FileLen(FileName) - 127
            Put #1, , .Tag
            Put #1, , .Songname
            Put #1, , .artist
            Put #1, , .album
            Put #1, , .year
            Put #1, , .comment
            Put #1, , .genre
      Close #1
End With
End Sub


Opening the file


Private Sub cmdOpen_Click()
With MediaPlayer1
      If Not FileOpen Then
            .FileName = FileName
            .AutoStart = False
            cmdOpen.Caption = "Close"
      Else
            .FileName = ""
            cmdOpen.Caption = "Open"
      End If
End With
End Sub


Calculating the duration


Private Sub MediaPlayer1_OpenStateChange(ByVal _
      OldState As Long, ByVal NewState As Long)

Min = MediaPlayer1.Duration  60
Sec = MediaPlayer1.Duration - (Min * 60)
lblTotalTime = "Total Time: " & Format(Min, "0#") _
      & ":" & Format(Sec, "0#") 'format time to 00:00
   
FileOpen = CBool(NewState)  
End Sub


Displaying the elapsed time


Private Sub Timer1_Timer()
Min = MediaPlayer1.CurrentPosition  60
Sec = MediaPlayer1.CurrentPosition - (Min * 60)
If Min > 0 Or Sec > 0 Then
      lblElapsedTime = "Elapsed Time: " & Format(Min, "0#") _
            & ":" & Format(Sec, "0#")
Else
      lblElapsedTime = "Elapsed Time: 00:00"
End If
End Sub


Remaining code


Private Sub EraseTXTBoxes()
lblMsg.Caption = ""
txtTitle = ""
txtArtist = ""
txtAlbum = ""
txtYear = ""
txtComment = ""
txtGenreCode = ""
Combo1.ListIndex = -1
End Sub
Private Sub Form_Load()
Dim x As Integer
Dim iLower As Integer
Dim iUpper As Integer

Drive1.Drive = "C:"
Dir1.Path = "C:"

GenresTypes = Array("Blues", "Classic Rock", "Country", _
      "Dance", "Disco", "Funk", "Grunge", "Hip -Hop", _
      "Jazz", "Metal", "New Age", "Oldies", "Other", _
      "Pop", "R&b", "Rap", "Reggae", "Rock", "Techno", _
      "Industrial", "Alternative", "Ska", "Death Metal", _
      "Pranks", "Soundtrack", "Euro -Techno", "Ambient", _
      "Trip -Hop", "Vocal", "Jazz Funk", "Fusion", _
      "Trance", "Classical", "Instrumental")

iLower = LBound(GenresTypes)
iUpper = UBound(GenresTypes)
For x = iLower To iUpper
      Combo1.AddItem GenresTypes(x)
Next x
End Sub


Hope this helps!
0
 

Author Comment

by:sofiansafy
ID: 6474346
Thanks master01 , its very simple to use.

My thanks also to Ardman for his great and useful details
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now