我正在尝试使用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!
视频没有停止!
怎么了?
答案 0 :(得分: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