Solved

Playing mp3 files

Posted on 2001-09-03
9
400 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

728 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