|
-
Feb 5th, 2005, 09:51 PM
#1
Thread Starter
Hyperactive Member
little help again (RESOLVED)
Hi all
I have received excellent help here and am back for a little more. I have an app that will write an xml file however it is currently writing it like this
<?xml version="1.0"?>
<songs>
<song path="my_mp3s\ 05 - Swamp.mp3" artist="Michael Kamen" title="05 - Swamp.mp3"/>
</songs>
But I need it to be displayed like this
<?xml version="1.0"?>
<songs>
<song path="my_mp3s/song.mp3"artist="" title=""/>
</songs>
I just need to remove the spacing nand change the slash here is the code that performs this but I'm not sure what needs changing I have played about with it but having no luck. Hop someone can help. Thanks
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mytag As Boolean
mp3path = "C:\mgamerz\my_mp3s\"
xmlpath = "C:\mgamerz\ "
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
' Artist = GetMP3Tag(fname)
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "You must close this form before continuing"
.Show
' .WindowState = 2
End With
TAG = "wait"
While TAG = "wait"
DoEvents
Wend
i = 1
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
' if you can return the name of the artist you put the code in here
mytag = GetMP3Tag(mp3path & SongName)
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
Close
End Sub
Last edited by robvr6; Feb 6th, 2005 at 12:42 AM.
Reason: resolved
-
Feb 5th, 2005, 10:13 PM
#2
Re: little help again
Here is the first part, which changes the slash.
VB Code:
pos=instr(mytag,"\")
mid(mytag,8,1)="/"
I am using this as a template.
mytag="my_mp3s\ 05 - Swamp.mp3"
it now looks like this:
my_mp3s/ 05 - Swamp.mp3
What else do you want done to it. Change it exactly. I can't tell if you want the track number removed, and the spaces, or what. Also, do you need to change the title at all?
-
Feb 5th, 2005, 10:22 PM
#3
Thread Starter
Hyperactive Member
Re: little help again
Hi David, thanks fo replying I bet your fed up with me lol.
All I think it needs changing is the slash and for there to be no spaces in the title of the track because its funny because it will work if the xml is hand coded for example if I had a mp3 track named rob.mp3 and I hand coded it like this it will work
<?xml version="1.0"?>
<songs>
<song path="my_mp3s/rob.mp3"artist="name" title="songname"/>
</songs>
So I am thinking that if there are no spaces it may work. Also where do I need to add the code you just posted.
Thanks
Rob
-
Feb 5th, 2005, 10:27 PM
#4
Re: little help again
Click Private Messages in the upper right hand corner. You have a PM.
Do you need the spaces removed only the first time?
-
Feb 5th, 2005, 10:29 PM
#5
Addicted Member
Re: little help again
maybe you can also use the Replace function to change all of a certain character in a string
-
Feb 5th, 2005, 10:36 PM
#6
Re: little help again
VB Code:
' if you can return the name of the artist you put the code in here
mytag = GetMP3Tag(mp3path & SongName)
pos = InStr(mytag, "\")
Mid(mytag, pos, 1) = "/"
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
This should be what you need. Let me know if it isn't! 
EDIT: You have to add Dim pos As Integer at the top
Last edited by dglienna; Feb 5th, 2005 at 10:52 PM.
-
Feb 5th, 2005, 10:37 PM
#7
Thread Starter
Hyperactive Member
Re: little help again
It is just the spaces before and after the slash that I think needs removing so its just like this because I think that is why the player cannot read it
<song path="my_mp3s/rob.mp3 "artist="name" title="songname"/>
thanks Rob
-
Feb 5th, 2005, 10:39 PM
#8
Re: little help again
my_mp3s/05-Swamp.mp3
the song remains the same
-
Feb 5th, 2005, 10:42 PM
#9
Thread Starter
Hyperactive Member
Re: little help again
do I need to declare pos as something because I get a compile error - variable not defined.
Cheers
Rob
-
Feb 5th, 2005, 10:45 PM
#10
Thread Starter
Hyperactive Member
Re: little help again
Mid(mytag, 8, 1) = type mismatch error.
ignore the previous post.
Rob
-
Feb 5th, 2005, 10:49 PM
#11
Re: little help again
oops. it worked as I stepped through it. You can delete the pos lines.
VB Code:
' mytag = "my_mp3s\ 05 - Swamp.mp3"
' pos = InStr(mytag, "\")
'Debug.Print pos
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
my_mp3s/05-Swamp.mp3
-
Feb 5th, 2005, 10:59 PM
#12
Thread Starter
Hyperactive Member
Re: little help again
<?xml version="1.0"?>
<songs>
<song path="my_mp3s\ The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs> Im still gettin it like this
Heres the code I think Ive changed everything right If poss would you check
thanks Rob
VB Code:
Private Sub Command2_Click()
Dim f1 As Integer, xmlpath As String, songpath As String, mp3path As String, f2 As Integer, i As Integer, pos As Integer
Dim Artist As String, SongName As String, artname As String, fname As String, MyPath As String
Dim mytag As Boolean
mp3path = "C:\mgamerz\my_mp3s\"
xmlpath = "C:\mgamerz\ "
SongName = Dir(mp3path & "\*.mp3")
fname = mp3path & SongName
With Form4
While Not Len(SongName) = 0
' Artist = GetMP3Tag(fname)
If Not i = 0 Then
Load .Label1(i): Load .Text1(i)
.Label1(i).Top = .Label1(i - 1).Top + 350
.Text1(i).Top = .Text1(i - 1).Top + 350
.Label1(i).Visible = True: .Text1(i).Visible = True
End If
.Label1(i) = SongName
mytag = GetMP3Tag(fname)
.Text1(i) = RTrim(MP3Info.sArtist)
SongName = Dir
fname = mp3path & SongName
i = i + 1
Wend
.Height = .Text1(.Text1.Count - 1).Top + 1600
.TAG = mp3path
MDIForm1.Caption = "You must close this form before continuing"
.Show
' .WindowState = 2
End With
TAG = "wait"
While TAG = "wait"
DoEvents
Wend
i = 1
f2 = FreeFile
Open mp3path & "mp3.txt" For Output As #f2
f1 = FreeFile
Open xmlpath & "audiolist.xml" For Output As #f1
Print #f1, "<?xml version=""1.0""?>"
Print #f1, "<songs>"
SongName = Dir(mp3path & "\*.mp3")
i = 1
While Not Len(SongName) = 0
' if you can return the name of the artist you put the code in here
mytag = GetMP3Tag(mp3path & SongName)
'pos = InStr(mytag, "\")
mytag = Replace(mytag, "\", "/")
Do While InStr(mytag, " ")
mytag = Replace(mytag, " ", "")
Loop
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
Print #f1, songpath
Print #f2, SongName
Sleep 100
SongName = Dir
Wend
Print #f1, "</songs>"
Close
End Sub
-
Feb 5th, 2005, 11:01 PM
#13
Re: little help again
that's right. the only thing that i would suggest would be to line everything up properly to make it easier to read and maintain. put everything 2,4,6, or 8 spaces from the left. it makes things easier to read.
I think that is what you need. Hope you are satisfied
-
Feb 5th, 2005, 11:06 PM
#14
Thread Starter
Hyperactive Member
Re: little help again
my xml is still coming out like this though <?xml version="1.0"?>
<songs>
<song path="my_mp3s\ The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
instead of this
<?xml version="1.0"?>
<songs>
<song path="my_mp3s/song.mp3"artist="" title=""/>
</songs>
sorry to mither
rob
-
Feb 5th, 2005, 11:09 PM
#15
Re: little help again
Hmm. I guess we don't need mypath anymore.
change this:
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
to
songpath = "<song path=""" & MyTag & """ artist=""" & Artist & """ title=""" & SongName & """/> "
-
Feb 5th, 2005, 11:14 PM
#16
Thread Starter
Hyperactive Member
Re: little help again
I did that but I got this
<?xml version="1.0"?>
<songs>
<song path="False" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
Rob
-
Feb 5th, 2005, 11:15 PM
#17
Re: little help again
or else, move the lines to below mypath, and change slightly.
VB Code:
Artist = RTrim(MP3Info.sArtist)
If Len(Artist) = 0 Then Artist = "UNKOWN"
MyPath = Right(mp3path, (Len(mp3path) - Len(xmlpath) + 1)) & " " & SongName
myPath = Replace(myPath, "\", "/")
Do While InStr(myPath, " ")
myPath = Replace(myPath, " ", "")
Loop
songpath = "<song path=""" & MyPath & """ artist=""" & Artist & """ title=""" & SongName & """/> "
I forgot that the path was wrong. I didn't have the program tonight.
-
Feb 5th, 2005, 11:30 PM
#18
Thread Starter
Hyperactive Member
Re: little help again
Thanks I think that has sorted it out finally. Can I ask advice again tomorrow when the person who is developing the flash tests it?
Thanks again
Rib
-
Feb 5th, 2005, 11:34 PM
#19
Re: little help again
Sure. I'll be around some of the time. Superbowl tomorrow, so I may be going out to watch it. If not, I'll be online.
Last edited by dglienna; Feb 5th, 2005 at 11:40 PM.
-
Feb 5th, 2005, 11:41 PM
#20
Thread Starter
Hyperactive Member
Re: little help again
Sorry just one quick question, How can i leave the spaces in the title of the track <song path="my_mp3s/The Streets - Weak Become Heroes.mp3".
its just the space after the slash that needs removing. Otherwise its working brilliant you know instead of this
<song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3"
-
Feb 6th, 2005, 12:00 AM
#21
Re: little help again
Try to change this:
VB Code:
Do While InStr(myPath, " ")
myPath = Replace(myPath, " ", "")
Loop
to this:
VB Code:
' Do While InStr(myPath, " ")
myPath = Replace(myPath, " ", "")
' Loop
it will just replace on space.
-
Feb 6th, 2005, 12:07 AM
#22
Thread Starter
Hyperactive Member
Re: little help again
it still does the same because all it needs is the name of the mp3 file to be the same as the original but before when it had spaces it left one after the slash which meant it didnt read the file correctly
-
Feb 6th, 2005, 12:12 AM
#23
Re: little help again
if you take out the do loop, it only removes one space. what is wrong? I am missing something.
-
Feb 6th, 2005, 12:18 AM
#24
Thread Starter
Hyperactive Member
Re: little help again
it is coming out like this
<?xml version="1.0"?>
<songs>
<song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
but I need it to come out like this
<?xml version="1.0"?>
<songs>
<song path="my_mp3s/The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
-
Feb 6th, 2005, 12:25 AM
#25
Re: little help again
ok, just delete the lines, instead of commenting them out.
Try to change this:
VB Code:
Do While InStr(myPath, " ")
myPath = Replace(myPath, " ", "")
Loop
to this:
VB Code:
myPath = Replace(myPath, " ", "")
if that doesn't work, post the code again...
oops. I just found something interesting.
VB Code:
myPath = Replace(myPath, " ", "",1,1)
the first number is the Start, and the second is Count.
this will ALWAYS remove one space from the string. hope that is good enough
Last edited by dglienna; Feb 6th, 2005 at 12:30 AM.
-
Feb 6th, 2005, 12:30 AM
#26
Thread Starter
Hyperactive Member
Re: little help again
still comin out like this
<song path="my_mp3s/TheStreets-WeakBecomeHeroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
instead of this'
<song path="my_mp3s/The Streets - Weak Become Heroes.mp3" artist="The Streets" title="The Streets - Weak Become Heroes.mp3"/>
</songs>
-
Feb 6th, 2005, 12:31 AM
#27
Re: little help again
I've edited my post. include ,1,1 for start and count (number of replaces)
i was told incorrect information. I thought the do loop was needed to keep removing spaces until the end, when only one would have removed them all.
we both learned something tonight.
Last edited by dglienna; Feb 6th, 2005 at 12:34 AM.
-
Feb 6th, 2005, 12:39 AM
#28
Thread Starter
Hyperactive Member
Re: little help again (RESOLVED)
Brilliant - Thanks very much indeed for all the help!!
Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|