我正在尝试用PHP编写一个跨平台的播放器,用于使用mplayer的特定视频格式。
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!视频不会停止!
怎么了?
发布于 2016-03-29 22:41:18
在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 Subhttps://stackoverflow.com/questions/10552321
复制相似问题