1

I'm trying to make a cross-platform player written in PHP for a particular video format using mplayer.
The PHP script builds the video file and launches mplayer, while it continues to build the video file.
Sometimes the PHP script it's not fast enough and mplayer crashes because it hasn't anymore bufferized video.
So, I need to control mplayer to pause it if I need buffering.
I made a function - just for test - that tries to stop video after 5 seconds.
(Here is a list of commands: http://www.mplayerhq.hu/DOCS/tech/slave.txt)

...
function OnClickButtonStart() {
    $mplayer = popen("mplayer -wid " .  $wid . " -slave -quiet -idle " . $filename . " > /dev/null 2> /dev/null  &", "w");
    var_dump($mplayer);
    sleep(5);
    echo "\nPausing...";
    fputs($mplayer, "pause\n");
    fflush($mplayer);
    echo "done!\n";
    return $mplayer;
}
... 

but, even if the output is:

resource(5) of type (stream)
Pausing...done!

the video doesn't stop!
What's wrong?

Matteo
  • 23
  • 6

1 Answers1

1

In VB.NET I use the following code to play mute and pause music. please use as you wish. Your problem is may be in sending command function i think.

    Private Sub funPlayMusic()
    ps = New Process()
    ps.StartInfo.FileName = "D:\Music\mplayer.exe "
    ps.StartInfo.UseShellExecute = False
    ps.StartInfo.RedirectStandardInput = True

    'ps.StartInfo.CreateNoWindow = True
    args = "-fs  -noquiet -identify -slave " '
    args += "-nomouseinput -sub-fuzziness 1 "
    args += " -vo direct3d, -ao dsound "
    '    -wid will tell MPlayer to show output inisde our panel
    '    args += " -vo direct3d, -ao dsound  -wid ";
    '    int id = (int)panel1.Handle;
    '    args += id;
End Sub


  Public Function SendCommand(ByVal cmd As String) As Boolean
    Try
        If ps IsNot Nothing AndAlso ps.HasExited = False Then
            ps.StandardInput.Write(cmd + vbLf)
            Return True
        Else
            Return False
        End If

    Catch ex As Exception
        Return False
    End Try
End Function 


   Public Sub Playsong(ByVal Songfilelocation As String)

    Try
        ps.Kill()
    Catch
    End Try
    Try
        ps.StartInfo.Arguments = args + " """ + Songfilelocation + """"
        ps.Start()

        SendCommand("set_property volume " + "80")
    Catch e As Exception
        MessageBox.Show(e.Message)
    End Try

End Sub


  Private Sub btnPause_Click(sender As Object, e As EventArgs) Handles       btnPlayPause.Click
    SendCommand("pause")


   End Sub


    Private Sub btnMute_Click(sender As Object, e As EventArgs) Handles btnMute.Click
    SendCommand("mute")


  End Sub
Blue Phoenix
  • 153
  • 11