Solved

Playing mp3 files

Posted on 2001-09-03
9
397 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 / DAO 3.6 / run time error: Couldn't find installable ISAM 7 102
MsgBox 2 59
How to make an ADE file by code? 11 94
Excel Automation VBA 19 88
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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…

840 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