Solved

Playing mp3 files

Posted on 2001-09-03
9
392 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

932 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

9 Experts available now in Live!

Get 1:1 Help Now