?
Solved

Playing mp3 files

Posted on 2001-09-03
9
Medium Priority
?
405 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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
 
LVL 20

Expert Comment

by:hes
ID: 6451390
0
 

Accepted Solution

by:
master01 earned 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
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…
Suggested Courses

649 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