1

我正在尝试使用 mplayer 为特定视频格式制作一个用 PHP 编写的跨平台播放器。
PHP 脚本构建视频文件并启动 mplayer,同时继续构建视频文件。
有时 PHP 脚本速度不够快,mplayer 会崩溃,因为它不再缓冲视频。
所以,如果我需要缓冲,我需要控制 mplayer 暂停它。
我做了一个功能 - 只是为了测试 - 试图在 5 秒后停止视频。
(这里是命令列表: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;
}
... 

但是,即使输出是:

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

视频停不下来!
怎么了?

4

1 回答 1

1

在 VB.NET 中,我使用以下代码来播放静音和暂停音乐。请随意使用。我认为您的问题可能在于发送命令功能。

    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
于 2016-03-29T14:41:17.797 回答