Problem with joining files
Posted: Mon Jun 16, 2003 2:56 am
I did a search of the forums and could not come up with anything on this subject. I'm trying to join multiple media files into one file and then play it back (files of the same type). I've done this successfully by using Copy on a command prompt and it works just fine. Using ReadData() and WriteData() within a program is not working. Can anyone tell me why this is? It puts the files together, but when you use a media player on the file, it halts after the first segment of whatever you put together.
Code: Select all
Procedure.l mod(num.l,div.l)
ProcedureReturn num - num / div * div
EndProcedure
#BUFFERSIZE = 2048
#FILE_OUT = 0
#FILE_IN = 1
NewList jfiles.s()
temp_item.s = OpenFileRequester("Select files","","",0,#PB_Requester_MultiSelection)
If temp_item
AddElement(jfiles())
jfiles() = Chr(27)
Repeat
AddElement(jfiles())
jfiles() = temp_item
temp_item = NextSelectedFileName()
Until temp_item = ""
*buffer = AllocateMemory(0,#BUFFERSIZE,0)
If *buffer
save_file.s = SaveFileRequester("Enter joined file name",GetPathPart(jfiles()) + "joined","",0)
If save_file
If IsFilename(GetFilePart(save_file) + GetExtensionPart(save_file))
save_flag.b = #TRUE
Else
save_flag.b = #FALSE
MessageRequester("Error","Illegal file name...",0)
EndIf
EndIf
If FileSize(save_file) > -1
Select MessageRequester("Alert!","File already exists. Overwrite?",#PB_MessageRequester_YesNo)
Case 7 ;* no button *
save_flag = #FALSE
EndSelect
EndIf
If FileSize(save_file) = -2
MessageRequester("Error","The name you have chosen is a directory...",0)
save_flag = #FALSE
EndIf
If save_flag
If CreateFile(#FILE_OUT,save_file)
Repeat
If ReadFile(#FILE_IN,jfiles())
UseFile(#FILE_IN)
i = Int(Lof() / #BUFFERSIZE)
write_count = 0
If i > 0
Repeat
UseFile(#FILE_IN)
ReadData(*buffer,#BUFFERSIZE)
UseFile(#FILE_OUT)
WriteData(*buffer,#BUFFERSIZE)
write_count + 1
Until write_count = i
EndIf
UseFile(#FILE_IN)
tail_length = mod(Lof(),#BUFFERSIZE)
ReadData(*buffer,tail_length)
UseFile(#FILE_OUT)
WriteData(*buffer,tail_length)
CloseFile(#FILE_IN)
Else
MessageRequester("Error","Unable to open " + jfiles() + "...",0)
EndIf
PreviousElement(jfiles())
Until jfiles() = Chr(27)
CloseFile(#FILE_OUT)
ClearList(jfiles())
FreeMemory(0)
MessageRequester("Message","Done",0)
Else
MessageRequester("Error","Unable to create joined file...",0)
EndIf
EndIf
Else
MessageRequester("Error","Unable to allocate memory...",0)
EndIf
EndIf