Winamp and Access

raindrop3

Registered User.
Local time
Today, 05:35
Joined
Sep 6, 2001
Messages
98
Hello,

I have a little mp3 database and i want to play a song when i click on a button. I can open winamp, but the song won't start. If i open winamp mannualy with a shortcut, I can play a song automaically, but in access it wont work.

Any ideas?

Thanks.

Albert
 
When you open the Winamp.exe I'm pretty sure you can supplly the mp3 filename as a parameter that will make it autoplay the song.

Let us know the outcome as this sounds like a great idea...
 
Hello,

I tryed the API-stuff and it works, but it don't support the .mp3 format. For wav it works fine.

Under a (play)button you can use code like this:

dim a
a = fPlayStuff("C:\WINDOWS\MEDIA\Microsoft Office 2000\applause.wav", 1)

under a stop button you can use:
dim b
b = b = fStopStuff("C:\WINDOWS\MEDIA\Microsoft Office 2000\applause.wav")

It works great, but when i try to play a mp3 file it won't play anything.

I tryed to open winamp and pass the filename with it like this:

Play = Shell("c:\program files\winamp\winamp.exe""c:\my music\mp3\africa.mp3")

but this also won't work.

Any ideas? (Is it possible that you need a special plug-in for opening winamp with a commandline?)

Greetings,

Albert
 
You can call winamp from a command line like this:

"c:\program files\winamp\winamp.exe" /ADD c:\music\file1.mp3

(double quotes are required if any part of the path contains spaces)

If you want to play multiple selections, you still use the /ADD command, but each subsequent filename has o be enclosed in quotes...

"c:\program files\winamp\winamp.exe"/ADD "c:\music\file2.mp3" "c:\music\file3.mp3"

Your best bet would be to work this up with the "Call Shell()" command in Access... I would use a control table to define the path to Winamp (that way you could define the path once & use the database across multiple systems if you needed to & if you move this to another PC with a different path, you would only have to update the table)

good luck, I hope this gets you on the right track...
 
Thanks jatfill! That worked great, but when the path to the mp3-file is in a variable, it gives a syntax-error. I tryed everything, but it won't work.

Now I can open winamp and play a song from access, but i had to program the path...I wan't to put it in a variable so, i can play every song i want. Hope you can help me with this...

Greetings,

Albert
 
can you post the current code you are using? It should be pretty easy to tweak & get it running...

Here's an example of a simple form with 2 text boxes and a button. Try creating it just to test with & go from there...

text box #1 - path to winamp
value = "C:\Program Files\winamp\winamp.exe" (be sure to include the double quotes)

text box #2 - path to file
value = C:\music\myfile.mp3 (same deal, if the path has spaces, use double quotes)

now for the OnClick command, try this (I didn't add the error handling or anything, but I did have a successful test of this code, my file came right up):

Private Sub cmdPlay_Click()
Dim stPath As String
Dim stFile As String

stPath = Me.txtBox1.Value
stFile = Me.txtBox2.Value

Call Shell(stPath & "/ADD" & stFile)


End Sub


[This message has been edited by jatfill (edited 02-11-2002).]
 
I was trying this out and found out that the ~~~Call Shell(stPath & "/ADD" & stFile)~~~ was giving me a problem. If you add a space after ADD it will work great!

ex.
Call Shell(stPath & "/ADD " & stFile)

Thanks jatfill, I am now going to have fun making my own mp3 player.



[This message has been edited by -td-shadow (edited 02-11-2002).]
 
Jatfill,

Thanks a lot for your help. It's working now! I found out the you can replace the /ADD part in /PLAY. Winamp play's the song immediately instead of placing it in the playlist.

When there are spaces in the path to the file, you can use the ~ to refer to the path. I.g. c:\my documts --> c:\mydo~1. It took some time, but now I can play songs in winamp, using access.(And others are also capable to do the same, I see...Great!)

Thanks for your time!

Greetings,

Albert
 
I didn't know about the /PLAY option, that will be really nice... I was looking at this & I might actually build my own... the possibilities are pretty neat... did either of you figure out a way to pull info from the ID2/3 tags on the files, or are you maintaining seperate databases with categories and such? It would be nice to create custom playlists based on your own information about the songs, then you could build queries/categories by artist, genre, etc. & pass entire playlists into winamp with a single click... very interesting...
 
heh. found this code on the web... might work for VBA...

Code:
' Create a new code module and paste this code into it:


Option Explicit

Public Type ID3Tag
    Header As String * 3
    SongTitle As String * 30
    Artist  As String * 30
    Album  As String * 30
    Year  As String * 4
    Comment As String * 30
    Genre  As Byte
End Type

Public Function GetID3Tag(FileName As String, Tag As ID3Tag) _
   As Boolean

'******************************
'Instructions:
'Pass an variable declared as type ID3Tag to Tag Parameter
'and read its member data after the function returns (assuming
'the function returns true)
'****************************

On Error GoTo GetID3TagError

Dim TempTag As ID3Tag
Dim FileNum As Long

    If Dir(FileName) = "" Then
        GetID3Tag = False
        Exit Function
    End If
    
    FileNum = FreeFile
    
    Open FileName For Binary As FileNum
    Get FileNum, LOF(1) - 127, TempTag
    Close FileNum
    
    If TempTag.Header <> "TAG" Then
        GetID3Tag = False
    Else
        Tag = TempTag
        GetID3Tag = True
    End If

    Exit Function

GetID3TagError:
    Close FileNum
    GetID3Tag = False
End Function
 
Here's another useful piece I found... the genre list based on the ID3v1/2 standards, which means you can pull the genre from the tag & map it to the correct description by building a table from the following data

*sigh* so much for getting any real work done this week... ;-)

(copy and paste this into notepad, save as .csv & you can import it directly into Access)
0,"Blues"
1,"Classic Rock"
2,"Country"
3,"Dance"
4,"Disco"
5,"Funk"
6,"Grunge"
7,"Hip-Hop"
8,"Jazz"
9,"Metal"
10,"New Age"
11,"Oldies"
12,"Other"
13,"Pop"
14,"R&B"
15,"Rap"
16,"Reggae"
17,"Rock"
18,"Techno"
19,"Industrial"
20,"Alternative"
21,"Ska"
22,"Death Metal"
23,"Pranks"
24,"Soundtrack"
25,"Euro-Techno"
26,"Ambient"
27,"Trip-Hop"
28,"Vocal"
29,"Jazz+Funk"
30,"Fusion"
31,"Trance"
32,"Classical"
33,"Instrumental"
34,"Acid"
35,"House"
36,"Game"
37,"Sound Clip"
38,"Gospel"
39,"Noise"
40,"AlternRock"
41,"Bass"
42,"Soul"
43,"Punk"
44,"Space"
45,"Meditative"
46,"Instrumental Pop"
47,"Instrumental Rock"
48,"Ethnic"
49,"Gothic"
50,"Darkwave"
51,"Techno-Industrial"
52,"Electronic"
53,"Pop-Folk"
54,"Eurodance"
55,"Dream"
56,"Southern Rock"
57,"Comedy"
58,"Cult"
59,"Gangsta"
60,"Top 40"
61,"Christian Rap"
62,"Pop/Funk"
63,"Jungle"
64,"Native American"
65,"Cabaret"
66,"New Wave"
67,"Psychadelic"
68,"Rave"
69,"Showtunes"
70,"Trailer"
71,"Lo-Fi"
72,"Tribal"
73,"Acid Punk"
74,"Acid Jazz"
75,"Polka"
76,"Retro"
77,"Musical"
78,"Rock & Roll"
79,"Hard Rock"
80,"Folk"
81,"Folk-Rock"
82,"National Folk"
83,"Swing"
84,"Fast Fusion"
85,"Bebob"
86,"Latin"
87,"Revival"
88,"Celtic"
89,"Bluegrass"
90,"Avantgarde"
91,"Gothic Rock"
92,"Progressive Rock"
93,"Psychedelic Rock"
94,"Symphonic Rock"
95,"Slow Rock"
96,"Big Band"
97,"Chorus"
98,"Easy Listening"
99,"Acoustic"
100,"Humour"
101,"Speech"
102,"Chanson"
103,"Opera"
104,"Chamber Music"
105,"Sonata"
106,"Symphony"
107,"Booty Bass"
108,"Primus"
109,"Porn Groove"
110,"Satire"
111,"Slow Jam"
112,"Club"
113,"Tango"
114,"Samba"
115,"Folklore"
116,"Ballad"
117,"Power Ballad"
118,"Rhythmic Soul"
119,"Freestyle"
120,"Duet"
121,"Punk Rock"
122,"Drum Solo"
123,"A capella"
124,"Euro-House"
125,"Dance Hall"
126,"Goa"
127,"Drum & Bass"
128,"Club-House"
129,"Hardcore"
130,"Terror"
131,"Indie"
132,"BritPop"
133,"Negerpunk"
134,"Polsk Punk"
135,"Beat"
136,"Christian Gangsta"
137,"Heavy Metal"
138,"Black Metal"
139,"Crossover"
140,"Contemporary Classical"
141,"Christian Rock"
142,"Merengue"
143,"Salsa"
144,"Thrash Metal"
145,"Anime"
146,"JPop"
147,"SynthPop"


[This message has been edited by jatfill (edited 02-12-2002).]
 
wow, pretty much allows for complete control!!

I have gotten the ID3 tag interface to work, I'm still debugging a little bit, but once I get all the kinks worked out I'm going to write a full module for the ID3 piece:

Automatically populate database with ID3 information from added files

Create new ID3 tags based on the information in your database(if the file does not have one)

Update ID3 tags automatically when you change file info in your tables

Remove ID3 information

so far all of this works for ID3v1 strictly, but I'm looking at the revisions to see how hard it would be..


I'll publish it here once I'm done if anyone else is interested... this is turning out to be a really fun project!
 
I developed this little code that reads files from a database and creates a PLAYLIST compatible with Winamp. It is much faster than the /ADD feature and you can select multiple files at once. I thought it could be useful here.

There is a table called SONGS with a field called [Path] with the full path and file name of all MP3 songs I want to select and play

_______________________________________
Code:
Private Sub Command39_Click()
Dim txtSQL, txtPrint As String
Dim i As Integer
Dim counter As Integer
Dim dbs As Database, rst As Recordset

        
    Rem Erase Playlist
    Open TempPath & "PLAYLIST.PLS" For Output As #1
    Close #1
    Rem done
    
    txtSQL = "SELECT Songs.* FROM Songs WHERE ([WSelect] <> 0) ORDER BY [Order], [Track]"
 
    i = 100
    Rem Max of 100 songs at same time
        
    Open TempPath & "PLAYLIST.PLS" For Append As #1
    Print #1, "[playlist]"
    
    counter = 1
    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset(txtSQL, DB_OPEN_DYNASET)
    Do Until (rst.EOF Or counter > i)
        txtPrint = "File" & counter & "=" & DefaultPath & rst![Path]
        Print #1, txtPrint
        counter = counter + 1
        rst.MoveNext
    Loop
    rst.Close
    Rem DoCmd.Close
   
   txtPrint = "NumberOfEntries=" & counter - 1
   Print #1, txtPrint
   Close #1
   Shell (WinampPath & " " & TempPath & "PLAYLIST.PLS")
   Rem WinampPath is a global variable = "C:\ProgramFiles\Winamp\winamp.exe"
   Rem TempPath is a global variable "C:\tmp\"
_________________________________________

I am trying now to update MP3 files ID3Tag info with info I have in my database and viceversa. If any of you know how to do this I would appreciate it...
 
OK, I think I have this sort of worked out now... this is a module I pulled from the web & modified for Access, so it may not be trouble-free. I've done some basic testing & it seems to work OK...

1. paste this into a new module:

Code:
Option Compare Database

Private mvarFilename As String
Private mvarArtist As String
Private mvarTitle As String
Private mvarAlbum As String
Private mvarComment As String
Private mvarGenre As Integer
Private mvarYear As String
Private tagData As String * 128
Public isActive As Boolean

Public Property Let Genre(ByVal vData As Integer)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If vData < 0 Or vData > 255 Then vData = 255
    Mid(tagData, 128, 1) = Chr(vData)
    mvarGenre = vData
End Property

Public Property Get Genre() As Integer
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Genre = mvarGenre
End Property

Public Property Let Comment(ByVal vData As String)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If Len(vData) > 30 Then vData = Left(vData, 30) 'If too big, trim to 30
    If Len(vData) < 30 Then vData = vData & String(30 - Len(vData), Chr(0)) 'If too small, fill the rest with nulls
    Mid(tagData, 98, 30) = vData
    mvarComment = vData
End Property

Public Property Get Comment() As String
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Comment = mvarComment
End Property

Public Property Let Album(ByVal vData As String)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If Len(vData) > 30 Then vData = Left(vData, 30) 'If too big, trim to 30
    If Len(vData) < 30 Then vData = vData & String(30 - Len(vData), Chr(0)) 'If too small, fill the rest with nulls
    Mid(tagData, 64, 30) = vData
    mvarAlbum = vData
End Property

Public Property Get Album() As String
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Album = mvarAlbum
End Property

Public Property Let Title(ByVal vData As String)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If Len(vData) > 30 Then vData = Left(vData, 30) 'If too big, trim to 30
    If Len(vData) < 30 Then vData = vData & String(30 - Len(vData), Chr(0)) 'If too small, fill the rest with nulls
    Mid(tagData, 4, 30) = vData
    mvarTitle = vData
End Property

Public Property Get Title() As String
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Title = mvarTitle
End Property

Public Property Let Artist(ByVal vData As String)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If Len(vData) > 30 Then vData = Left(vData, 30) 'If too big, trim to 30
    If Len(vData) < 30 Then vData = vData & String(30 - Len(vData), Chr(0)) 'If too small, fill the rest with nulls
    Mid(tagData, 34, 30) = vData
    mvarArtist = vData
End Property

Public Property Get Artist() As String
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Artist = mvarArtist
End Property

Public Property Let filename(ByVal vData As String)
    Dim fileNum As Long, filePos As Long
    
    If Len(Dir(vData)) = 0 Then
        GoTo WRONG
    Else
        If UCase(Right(vData, 4)) <> ".MP3" Then GoTo WRONG
        fileNum = FreeFile
        filePos = FileLen(vData) - 127
        If filePos > 0 Then
            Open vData For Binary As #fileNum
                Get #fileNum, filePos, tagData
            Close #fileNum
            If Left(tagData, 3) <> "TAG" Then GoTo WRONG
            
            mvarTitle = Replace(Trim(Mid(tagData, 4, 30)), Chr(0), "")
            mvarArtist = Replace(Trim(Mid(tagData, 34, 30)), Chr(0), "")
            mvarAlbum = Replace(Trim(Mid(tagData, 64, 30)), Chr(0), "")
            mvarYear = Replace(Trim(Mid(tagData, 94, 4)), Chr(0), "")
            mvarComment = Replace(Trim(Mid(tagData, 98, 30)), Chr(0), "")
            mvarGenre = Asc(Mid(tagData, 128, 1))
        Else
            GoTo WRONG
        End If
    End If
    
    isActive = True
    mvarFilename = vData
    Exit Property
WRONG: ' Jumps here if bad file
    isActive = False
    mvarFilename = ""
End Property

Public Property Get filename() As String
    filename = mvarFilename
End Property

Public Property Let Year(ByVal vData As String)
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    If Len(vData) > 4 Then vData = Left(vData, 4) 'If too big, trim to 30
    If Len(vData) < 4 Then vData = vData & String(4 - Len(vData), Chr(0)) 'If too small, fill the rest with nulls
    Mid(tagData, 94, 4) = vData
    mvarYear = vData
End Property

Public Property Get Year() As String
    If (Len(Dir(mvarFilename))) = 0 Then Exit Property
    Year = mvarYear
End Property

Public Function SaveTag() As String
    Dim errDesc As String ' Error description
    Dim fileNum As Long, filePos As Long
    Dim filedata As String
    
    If Len(Dir(mvarFilename)) = 0 Then
        errDesc = "File not found"
        GoTo WRONG
    Else
        If UCase(Right(mvarFilename, 4)) <> ".MP3" Then errDesc = "Wrong file extension. Must be .mp3": GoTo WRONG
        fileNum = FreeFile
        filedata = String(FileLen(mvarFilename), Chr(0)) 'Buffer
        nTag = "TAG"
        
        If FileLen(mvarFilename) > 128 Then
            Open mvarFilename For Binary As #fileNum
                Get #fileNum, 1, filedata
            Close #fileNum
            
            If Left(Right(filedata, 128), 3) <> "TAG" Then GoTo WRONG
               Mid(filedata, Len(filedata) - 127) = tagData
            
            fileNum = FreeFile
            Open mvarFilename For Binary As #fileNum
                Put #fileNum, 1, filedata
            Close #fileNum
        
        Else
            GoTo WRONG
        End If
    End If
    
    Exit Function
    

WRONG: 'Go here if error writing to file
    isActive = False
    mvarFilename = ""
    SaveTag = errDesc
    
End Function

I don't want to make one huge thread, so...
 
... the module above won't create a new tag, so I had to write another one to accomplish this task. I'll eventually combine them so it's a little more transparent, but again if someone else does it and sends it to me, I'm not likely to complain ;-)

2. this is a second module, to create ID3v1 mp3 tags if a file has none:

Code:
Option Compare Database
Public Function NewID3(strFileName As String)
    
On Error GoTo ErrHandler

    Dim newData As String 'seperate read and write files
    Dim curdata As String
    
        
    
    readfileNum = FreeFile
    writeFileNum = FreeFile
    curdata = String(FileLen(strFileName), Chr(0)) 'Buffer
    
    
        Open strFileName For Binary As #readfileNum
        Get #readfileNum, 1, curdata
        Close #readfileNum
    
    If Left(Right(curdata, 128), 3) = "TAG" Then  'check to see if tag exists
        MsgBox strFileName & " already contains ID3 information.", vbOKOnly, "Unable to Write"
        Exit Function
    End If
            
            newData = "TAG" & String(125, Chr(0))
            Open strFileName For Binary As #writeFileNum 'open file again and create a new blank ID3v1 tag
                Put #writeFileNum, FileLen(strFileName) + 1, newData
            Close #writeFileNum
            
ErrHandler:
    Close #readfileNum
    Close #writeFileNum
    MsgBox Err.Description, , Err.Number
    Exit Function
    
    
End Function

and of course, there's implementation...
 
**These are just snippets, you'll need to incorporate them into full event procedures (button clicks, etc.)**

so to call the first module (write and/or modify existing tags), you'd use something like this:

1. Update a tag from your database values:
Code:
MP3.filename = strInputFileName 'get the file

If MP3.isActive = True Then
    
Dim nGenre As String
    If MP3.Genre > 147 Then 'Genre information... current support is up to 147, 148 marks it as Unknown
        nGenre = "148"
    Else
        nGenre = MP3.Genre
    End If
    
    'Change the ID3 information, replace Me.* values with your variables
    MP3.Artist = Me.txtTag
    MP3.Title = Me.txtTitle
    MP3.Album = Me.txtAlbum    MP3.Comment = Me.txtComment
    MP3.Year = Me.txtYear
    MP3.Genre = Me.intGenre
MP3.SaveTag 'Saves the new ID3 information
End If

2. Write tag info from an mp3 file to fields in a table:

Code:
MP3.filename = strInputFileName 'get the file

If MP3.isActive = True Then
Dim nGenre As String
    If MP3.Genre > 147 Then 'Genre information... current support is up to 147, 148 marks as Unknown
        nGenre = "148"
    Else
        nGenre = MP3.Genre
    End If
DoCmd.RunSQL "INSERT INTO tblMusic ( filepath, Tag, Artist, Title, Album, Comment, Year, genreID )" & _
            " SELECT '" & strInputFileName & "' AS tFile, 'TAG' AS tTag, '" & 

MP3.Artist & "' AS tArtist, '" & MP3.Title 

& "' AS tTitle, '" & MP3.Album & "' AS 

tAlbum, '" & MP3.Comment & "' AS 

tComment, '" & MP3.Year & "' AS tYear, '" & _
            nGenre & "' AS tGenre;"
Me.lstMusic.Requery
            
            


Else 'No ID3 Info: Import the file and then call the edit form to add file info. Then you can create tag & update
    DoCmd.RunSQL "INSERT INTO tblMusic (filepath)" & _
            " SELECT '" & strInputFileName & "' AS tFile;"
    Dim newFileID As String
        newFileID = DLookup("[ID]", "tblMusic", "[filepath] = '" & strInputFileName & "'")
        
    DoCmd.OpenForm "frmEdit", acNormal, , "[ID] = " & newFileID
    Forms!frmEdit.AllowAdditions = False
  
End If

3. To write the blank tag, just call the following:
Code:
NewID3(strFileName)
much simpler than the above, the strFileName is whatever file (full path) you want to create a new tag into.


[This message has been edited by jatfill (edited 02-26-2002).]
 
Great jatfill... Thank you very much!!

I was away last week. I´ll work on it as soon as I am back home... I´ll let you know my progress...

Thx again
wink.gif
 

Users who are viewing this thread

Back
Top Bottom