Hi,
I discovered that the AudioDjStudioApi cannot play audio files in a playlist within a command line program.
I modified the sample program "PlayerCmdLine" so that the program can load a directory containing audio source files and play them, but it seems to be unsuccessful. It can load a single audio file and play but a playlist. The program code is as follows. Is there anything I'm missing?
'---------------------------------------------------------------
Namespace PlayerCmdLine
Friend Class Program
Private Shared m_bSoundDone As Boolean = False
Private Shared m_strInputPathname As String = ""
Private Shared addrCallbackForPlayersEvents As CallbackForPlayersEvents = New CallbackForPlayersEvents(AddressOf PlayerCallback)
Private Shared m_audioAPI As AudioDjStudioApi.AudioDjStudioApiObj = New AudioDjStudioApi.AudioDjStudioApiObj()
Private Shared Sub PlayerCallback(ByVal nEvent As enumPlayerEvents, ByVal nPlayer As Int16, ByVal nData1 As Int32, ByVal nData2 As Int32, ByVal fData3 As Single, ByVal pBufferUnicode As IntPtr, ByVal nBufferLength As Int32)
Select Case nEvent
Case enumPlayerEvents.EV_SOUND_DONE
Console.WriteLine(Constants.vbCr & nEvent.ToString)
m_bSoundDone = True
Case enumPlayerEvents.EV_SOUND_PLAYING
Console.WriteLine(Constants.vbCr & "Status: Sound playing...")
Case enumPlayerEvents.EV_PLAYLIST_LOAD_DONE
Console.WriteLine(Constants.vbCr & nEvent.ToString)
If nData1 = 0 Then
Console.WriteLine(Constants.vbCr & "Error loading playlist")
End If
Case enumPlayerEvents.EV_PLAYLIST_DONE
Console.WriteLine(Constants.vbCr & nEvent.ToString)
Case enumPlayerEvents.EV_PLAYLIST_LOAD_STARTED
Console.WriteLine(Constants.vbCr & nEvent.ToString)
Case Else
Return
End Select
End Sub
Shared Sub Main(ByVal args As String())
If args Is Nothing Then
Console.WriteLine("args is null") ' Check for null array
Return
End If
' read command line arguments
Dim prefixes As String() = New String() {"/i:"}
Dim cae As CmdArgExtractor = New CmdArgExtractor(prefixes, "/"c, ":"c)
If (Not cae.ValidArgsPrefixes(args)) Then
Return
End If
Dim my2dArr As String(,) = cae.GetArgsTwoDimArray(args)
Dim i As Integer = 0
Do While i < my2dArr.GetLength(1)
Select Case my2dArr(0, i)
Case "i"
m_strInputPathname = my2dArr(1, i)
End Select
i += 1
Loop
Console.Clear()
m_audioAPI.InitSoundSystem(1, 0, 0, 0, 0)
m_audioAPI.CallbackForPlayersEventsSet(addrCallbackForPlayersEvents)
m_audioAPI.DisplayVUMeter.Create(0, IntPtr.Zero)
m_audioAPI.StreamVolumeLevelSet(0, 100, enumVolumeScales.SCALE_LINEAR)
Dim err As enumErrorCodes
Select Case True
Case Directory.Exists(m_strInputPathname)
For Each file As String In Directory.GetFiles(m_strInputPathname)
err = m_audioAPI.PlayListAddItem(0, m_strInputPathname, 0)
Console.WriteLine("{0} {1}", file, err.ToString)
Next
Console.WriteLine(m_audioAPI.PlayListExecute(0, True).ToString)
Case File.Exists(m_strInputPathname)
err = m_audioAPI.LoadSound(0, m_strInputPathname)
Console.WriteLine("{0} {1}", m_strInputPathname, err.ToString)
Console.WriteLine(m_audioAPI.PlaySound(0).ToString)
End Select
If m_audioAPI.LastError <> enumErrorCodes.ERR_NOERROR Then
Console.WriteLine("Cannot load file due to error " & m_audioAPI.LastError.ToString)
Else
Dim info As ConsoleKeyInfo = New ConsoleKeyInfo()
Do While Not Console.KeyAvailable
If m_bSoundDone Then
Exit Do
End If
Thread.Sleep(50)
Loop
m_audioAPI.StopSound(0)
Console.WriteLine(Constants.vbCrLf & "Status: Stop")
End If
m_audioAPI.Dispose()
End Sub
End Class
End Namespace
'---------------------------------------------------------------
Terry
Hello,
the main error is caused by the fact that you are not passing the correct file pathname to the PlayListAddItem method. Try to change the following code
For Each file As String In Directory.GetFiles(m_strInputPathname)
err = m_audioAPI.PlayListAddItem(0, m_strInputPathname, 0)
Console.WriteLine("{0} {1}", file, err.ToString)
Next
with the following code:
For Each file As String In Directory.GetFiles(m_strInputPathname)
err = m_audioAPI.PlayListAddItem(0, file, 0)
Console.WriteLine("{0} {1}", file, err.ToString)
Next
Another problem is the fact that you set the following code inside the handler of the enumPlayerEvents.EV_SOUND_DONE event, causing the playlist being stopped after the first song
m_bSoundDone = True
please, move that line inside the handler of the enumPlayerEvents.EV_PLAYLIST_DONE event instead.
Another important point: The original source code of the Visual Basic.NET version of the PlayerCmdLine project (so also your code) contains the following line:
Thread.Sleep(50)
Be sure to replace this line with the following one or your application may experience several malfunctions
m_audioAPI.ConsoleWait(50)
Hope this helps.
Severino Delaurenti
I was so careless, thank you.
Hello,
you are welcome ;D
Kind regards
Severino Delaurenti
MultiMedia Soft