fizzlefry
asked on
Play MP3 files in reverse using MCISendString and .NET
I have an unusual question.
Recently I developed a program, for my own pleasure, that would allow for multiple MP3 files to be played simultaneously. I did this for a specific band that put out a series of albums. More details, if you'd like... Anyway, the exampled code is pieces of the program for the sake of functionality reference:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32) As Int32
Dim WithEvents PlayerWM As New WMPLib.WindowsMediaPlayer
' Play Function
' Disregard the loop, as that is how I accomplish the multiple file playing
For i As Integer = 0 To LBTracks.Items.Count - 1
Dim filename As String = LBTracks.Items(i).ToString
mciSendString("open """ & filename & """ type mpegvideo alias audiofile" & i & "", Nothing, 0, IntPtr.Zero)
Dim playCommand As String = "play audiofile" & i & " from 0"
mciSendString(playCommand, Nothing, 0, IntPtr.Zero)
Next
' Pause Function - for additional reference
For i As Integer = 0 To LBTracks.Items.Count - 1
Dim pauseCommand As String = "pause audiofile" & i & ""
mciSendString(pauseCommand , Nothing, 0, IntPtr.Zero)
Next
Anyway, as I thought more about the program, I thought it would be FANTASTIC to have the option to play an MP3 file in reverse, since it was likely that would be an option. Google has been very tight-lipped on the subject, and I can't find anything through the forums here. I was really hoping someone could give me some helpful advice. I'm still a novice with this line of programming, so any and all help would be really appreciated.
Recently I developed a program, for my own pleasure, that would allow for multiple MP3 files to be played simultaneously. I did this for a specific band that put out a series of albums. More details, if you'd like... Anyway, the exampled code is pieces of the program for the sake of functionality reference:
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Int32, ByVal hwndCallback As Int32) As Int32
Dim WithEvents PlayerWM As New WMPLib.WindowsMediaPlayer
' Play Function
' Disregard the loop, as that is how I accomplish the multiple file playing
For i As Integer = 0 To LBTracks.Items.Count - 1
Dim filename As String = LBTracks.Items(i).ToString
mciSendString("open """ & filename & """ type mpegvideo alias audiofile" & i & "", Nothing, 0, IntPtr.Zero)
Dim playCommand As String = "play audiofile" & i & " from 0"
mciSendString(playCommand,
Next
' Pause Function - for additional reference
For i As Integer = 0 To LBTracks.Items.Count - 1
Dim pauseCommand As String = "pause audiofile" & i & ""
mciSendString(pauseCommand
Next
Anyway, as I thought more about the program, I thought it would be FANTASTIC to have the option to play an MP3 file in reverse, since it was likely that would be an option. Google has been very tight-lipped on the subject, and I can't find anything through the forums here. I was really hoping someone could give me some helpful advice. I'm still a novice with this line of programming, so any and all help would be really appreciated.
The problem with that is that MP3's are encoded in blocks. You would have to decode the block to raw data and then feed it backwards to the audio chipset.
ASKER
DaveBaldwin, I really appreciate your response. I understand the logic behind what you're saying, I'm just not sure of the application. Can you help me get started with this? Again, I apologize, but I'm just venturing into audio file playing so I'm still learning a lot of this. Thanks!
No, I don't think this is going to happen. Right now you are relying on WindowsMediaPlayer to do the decoding that is required and send the decoded audio to the sound system. To play MP3s backwards, I believe that you would have write all the low level code that decodes the MP3s starting from the end and feed it to the audio system yourself.
ASKER
As far as the multiple track deal, I will NOT be allowing multiple tracks to be played in reverse. This was going to be solely for a singular track. And as far as using WMP in the code, I have no problems changing the concept, just for this function. So if there would be a better way to do it, and still accomplish what I need, I can easily move away from WMP for the playing in reverse function (leaving the rest of the code intact). Does that make it easier, harder, or still not going to be possible?
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thanks for the link. Unfortunately, I'm unsure where to go from here (I dl'ed Cool Edit MP3 decoder, which is apparently in C/C++ and that's about it). Most of my experience is in VB.NET. Although I realize there are some similarities between that and C, I just don't know if I'd know what to do with this source code. And if I could get it decoded properly, I don't know how to even start feeding it back manually to the audio chipset. Again, I really appreciate your help with this, but could you offer up some additional references? Why exactly would VB.NET not be the proper solution for this? Like I said, I'm eternally grateful, but I'm somewhat stuck at this point.
I don't believe that VB.NET will provide the appropriate low-level access that you need to do that. C/C++ and assembly language are generally used for things like this. The only time I have done anything like this was 20 years ago in C and assembly language in DOS.