【问题标题】:How to write Remote-Control program for mplayer?如何为 mplayer 编写远程控制程序?
【发布时间】:2016-03-30 12:39:13
【问题描述】:

我需要创建一个NPAPI-Browser插件来控制mplayer,我发现控制mplayer的一种方法是它的slave模式[link],还有其他更好的方法吗?

【问题讨论】:

    标签: linux controls mplayer


    【解决方案1】:

    不是你的问题,我知道。但是 VLC 具有类似级别的编解码器支持,可使用 lua 脚本扩展的集成 Web 界面,并且您可能不想要的所有内容(如 OSD)都可以关闭。 VLC 也可以通过 telnet 进行控制,并且 lua 库很容易扩展以允许网络接口或您可能想要的任何其他内容。我写了一个插件来允许串行线控制。

    【讨论】:

      【解决方案2】:

      发现只有mplayer slave模式,ftp://ftp2.mplayerhq.hu/MPlayer/DOCS/tech/slave.txt

      【讨论】:

        【解决方案3】:

        我正在开发android手机遥控器+VB.NET TCP服务器-mplayer。我在从属模式下使用 mplayer。我从 android 应用程序向 VB.NET TCP 服务器发送命令。然后命令将发送到 mplayer。

        我将展示一些控制和发送 mplayer 所需命令的代码,但服务器部分还没有完成。代码还没写完,希望对你有用。

        Imports System.ComponentModel
        Imports System.IO
        Imports System.Data.OleDb
            Public Class Form1
              Private bw As BackgroundWorker = New BackgroundWorker
              Dim i As Integer = 0
              Dim dbFile As String = Application.StartupPath & "\Data\Songs.accdb"
              Public connstring As String = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & dbFile & "; persist security info=false"
              Public conn As New OleDbConnection(connstring)
              Dim sw As Stopwatch
              Dim ps As Process = Nothing
              Dim jpgPs As Process = Nothing
              Dim args As String = Nothing
              Private Sub bw_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
                 Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)
        
                 If bw.CancellationPending = True Then
                     e.Cancel = True
                     Exit Sub
                 Else
                ' Perform a time consuming operation and report progress.
                'System.Threading.Thread.Sleep(500)
                bw.ReportProgress(i * 10)
                Dim dir_info As New DirectoryInfo(TextBox1.Text)
                ListFiels("SongList", TextBox2.Text, dir_info)
            End If
        
         End Sub
        
           Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
            If e.Cancelled = True Then
                Me.tbProgress.Text = "Canceled!"
            ElseIf e.Error IsNot Nothing Then
                Me.tbProgress.Text = "Error: " & e.Error.Message
            Else
                Me.tbProgress.Text = "Done!"
            End If
        End Sub
        
          Private Sub bw_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs)
               Me.tbProgress.Text = e.ProgressPercentage.ToString() & "%"
          End Sub
        
          Private Sub Form1_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
                Try
                   ps.Kill()
                Catch
                    Debug.Write("already closed")
                End Try
            End Sub
        
        
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False 'To avoid error from backgroundworker
            bw.WorkerReportsProgress = True
            bw.WorkerSupportsCancellation = True
            AddHandler bw.DoWork, AddressOf bw_DoWork
            AddHandler bw.ProgressChanged, AddressOf bw_ProgressChanged
            AddHandler bw.RunWorkerCompleted, AddressOf bw_RunWorkerCompleted
            funPlayMusic()
        End Sub
        
        Private Sub buttonStart_Click(sender As Object, e As EventArgs) Handles buttonStart.Click
            If Not bw.IsBusy = True Then
                bw.RunWorkerAsync()
            End If
        End Sub
        
        Private Sub buttonCancel_Click(sender As Object, e As EventArgs) Handles buttonCancel.Click
            If bw.WorkerSupportsCancellation = True Then
                bw.CancelAsync()
            End If
        End Sub
        
        Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
            If Not bw.IsBusy = True Then
                sw = Stopwatch.StartNew()
                bw.RunWorkerAsync()
                sw.Stop()
                Label1.Text = ":   " + sw.Elapsed.TotalMilliseconds.ToString() + " ms"
            End If
        End Sub
        Private Sub ListFiels(ByVal tblName As String, ByVal pattern As String, ByVal dir_info As DirectoryInfo)
            i = 0
            Dim fs_infos() As FileInfo = Nothing
            Try
                fs_infos = dir_info.GetFiles(pattern)
            Catch ex As Exception
                MessageBox.Show(ex.ToString())
            End Try
        
        
            For Each fs_info As FileInfo In fs_infos
                i += 1
                Label1.Text = i
                insertData(tblName, fs_info.FullName)
                lstResults.Items.Add(i.ToString() + ":" + fs_info.FullName.ToString())
                If i = 1 Then
                    Playsong(fs_info.FullName.ToString())
                Else
                    i = 0
                    lstResults.Items.Clear()
                End If
            Next fs_info
            sw.Stop()
            Label1.Text = ":   " + sw.Elapsed.TotalMilliseconds.ToString() + " ms"
            fs_infos = Nothing
        
            Dim subdirs() As DirectoryInfo = dir_info.GetDirectories()
            For Each subdir As DirectoryInfo In subdirs
                ListFiels(tblName, pattern, subdir)
            Next
        
        End Sub
        Private Sub insertData(ByVal tableName As String, ByVal foundfile As String)
            Try
                If conn.State = ConnectionState.Open Then conn.Close()
                conn.Open()
        
                Dim SqlQuery As String = "INSERT INTO " & tableName & " (SngPath) VALUES (@sng)"
                Dim SqlCommand As New OleDbCommand
                With SqlCommand
                    .CommandType = CommandType.Text
                    .CommandText = SqlQuery
                    .Connection = conn
                    .Parameters.AddWithValue("@sng", foundfile)
                    .ExecuteNonQuery()
                End With
        
                conn.Close()
            Catch ex As Exception
                conn.Close()
                MsgBox(ex.Message)
            End Try
        End Sub
        
        
        Private Sub btnClearList_Click(sender As Object, e As EventArgs) Handles btnClearList.Click
            lstResults.Items.Clear()
        End Sub
        
        Private Sub funPlayMusic()
        
            ps = New Process()
            ps.StartInfo.FileName = "D:\Music\mplayer.exe "
            ps.StartInfo.UseShellExecute = False
            ps.StartInfo.RedirectStandardInput = True
            jpgPs = New Process()
            jpgPs.StartInfo.FileName = "D:\Music\playjpg.bat"
            jpgPs.StartInfo.UseShellExecute = False
            jpgPs.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)
                    'MessageBox.Show(ps.StandardOutput.ReadToEndAsync.ToString())
                    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 lstResults_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstResults.SelectedIndexChanged
            Playsong(lstResults.SelectedItem.ToString())
        End Sub
        
        
        
        Private Sub btnPlayJPG_Click(sender As Object, e As EventArgs) Handles btnPlayJPG.Click
            Try
                ' jpgPs.Kill()
            Catch
            End Try
            Try
                'ps.StartInfo.Arguments = "–fs –mf fps=5 mf://d:/music/g1/Image00020.jpg –loop 200" '-vo gl_nosw
                'jpgPs.Start()
                Shell("d:\Music\playjpg.bat")
        
                ' SendCommand("set_property volume " + "80")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
        
        
        Private Sub btnPlayPause_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
        
        Private Sub btnKaraoke_Click(sender As Object, e As EventArgs) Handles btnKaraoke.Click
            'SendCommand("panscan 0-0 | 1-1")
            SendCommand("af_add pan=2:1:1:0:0")
        
        
        End Sub
        
        Private Sub btnStereo_Click(sender As Object, e As EventArgs) Handles btnStereo.Click
            SendCommand("af_add pan=2:0:0:1:1")
        End Sub
        
        Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
            Playsong("d:\music\iot.mp4")
        End Sub
        
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            'SendCommand("loadfile d:\music\iot.mp4")
            'SendCommand("pt_step 1")
        
        End Sub
        
        End Class
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-10
          • 2015-05-22
          • 2011-01-18
          • 1970-01-01
          相关资源
          最近更新 更多