Announcement

Collapse
No announcement yet.

Audio CD player script problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Audio CD player script problems

    Guys..

    I'm trying to write a small script that will play an audio CD on my HS PC, I'm told the WMP plugin does not support the playing of them so it looks like i'm going to have to write a script for it.

    I've looked around the net and found a few scripts however I can't get them to run on the HS PC. Most involve the MCI interface which I believe is from the VB6 days...

    Here is the code for a standalone Vb.net app which works fine on the PC;

    Public Class Form1
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    Dim cdDrive As String = "F:\" '<- This is your CD Drive
    Dim retVal As Integer
    Dim buf As String = Space(128)
    Dim buf2 As String = Space(128)
    Dim trackCount As Integer
    Dim currentTrack As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    cdDrive = Chr(34) & cdDrive & Chr(34) 'Puts "" Areound the CD Drive "D:\"
    retVal = mciSendString("open " & cdDrive & " type cdaudio alias cd wait shareable", vbNullString, 0, 0)
    retVal = mciSendString("set cd time format tmsf", vbNullString, 0, 0) 'This will set it so the tracks are recognized as 1 2 3 4...
    retVal = mciSendString("status cd number of tracks", buf, 128, 0) 'Get Num. Of Tracks
    retVal = mciSendString("status cd current track", buf2, 128, 0) 'Get Current Track
    trackCount = CInt(Val(buf)) 'This Will Get the Number Of Tracks (Convert it Into 1 2 3 4...)
    currentTrack = CInt(Val(buf2)) 'This Will get the Current Track (Convert it Into 1 2 3 4...)
    Label1.Text = currentTrack & "/" & trackCount
    NumericUpDown1.Maximum = trackCount + 1
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    retVal = mciSendString("status cd current track", buf2, 128, 0) 'This will get the current Track
    currentTrack = CInt(Val(buf2)) 'Converts it into 1 2 3 4...
    Label1.Text = currentTrack & "/" & trackCount
    NumericUpDown1.Value = currentTrack
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    retVal = mciSendString("play cd", vbNullString, 0, 0) 'Plays the CD
    End Sub
    End Class
    I've written a script in HS which is this;

    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer

    Dim cdDrive As String = "F:\" '<- This is your CD Drive
    Dim retVal As Integer
    Dim buf As String = Space(128)
    Dim buf2 As String = Space(128)
    Dim trackCount As Integer
    Dim currentTrack As Integer

    Sub Main(ByVal Data As Object)

    Dim buf As String = Space(128)
    cdDrive = Chr(34) & cdDrive & Chr(34) 'Puts "" Areound the CD Drive "D:\"
    retVal = mciSendString("open " & cdDrive & " type cdaudio alias cd wait shareable", vbNullString, 0, 0)
    retVal = mciSendString("set cd time format tmsf", vbNullString, 0, 0) 'This will set it so the tracks are recognized as 1 2 3 4...

    retval = mciSendString("stop cd wait", 0, 0, 0)
    retVal = mciSendString("status cd number of tracks wait", buf, 128, 0) 'Get Num. Of Tracks
    retVal = mciSendString("status cd current track", buf2, 128, 0) 'Get Current Track
    trackCount = CInt(Val(buf)) 'This Will Get the Number Of Tracks (Convert it Into 1 2 3 4...)
    currentTrack = CInt(Val(buf2)) 'This Will get the Current Track (Convert it Into 1 2 3 4...)

    hs.writelog("TestCD", currentTrack & "/" & trackCount)

    'retVal = mciSendString("play cd", vbNullString, 0, 0) 'Plays the CD

    End Sub
    Curiously the current track reports correctly (if I have a CD playing in another application), but I can't get it to play/stop/pause or report the current track number (reports 0)

    Anyone any ideas? Or other ideas for different code?

    Thanks...

    #2
    Never fear..I got a bit impatient so I created a form less vb.net application, a script and a few devices and have the stand alone app talking between HS and the cd player and script commands to change the track/start/stop/pause.

    Seems to work OK, just got to get it into HSTouch now..

    Thanks for reading.

    Comment

    Working...
    X