2012-05-11 59 views
1

我試圖讓用PHP編寫用mplayer特定的視頻格式,跨平臺的播放器。
PHP腳本構建視頻文件並啓動mplayer,同時繼續構建視頻文件。
有時PHP腳本不夠快,mplayer崩潰,因爲它沒有緩存視頻。
所以,我需要控制mplayer暫停它,如果我需要緩衝。
我製作了一個功能 - 僅用於測試 - 嘗試在5秒後停止視頻。
(這裏是命令的列表:http://www.mplayerhq.hu/DOCS/tech/slave.txt從MPlayer的PHP

... 
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

您是否嘗試過'暫停'而沒有\ n?你嘗試過'暫停'嗎? (在http://www.mplayerhq.hu/DOCS/tech/slave.txt中可以看到) –

+0

我已經嘗試過了,但沒有一個能夠工作...... – Matteo

回答

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