如何在vb.net中检测vlc视频播放中的当前位置? [英] how do i detect the current position in vlc video-playback in vb.net?
问题描述
如何在vb.net中检测vlc视频播放中的当前位置?
基本上当剪辑正在播放时,我想在标签中找到它说02:58/21:35与正在播放的当前片段有关。
所以我需要以某种方式弄清楚如何检测当前位置和结束位置。有谁知道怎么做?
到目前为止代码:
how do i detect the current position in vlc video-playback in vb.net?
Basically as the clip is playing, I want in a label for it to say "02:58/21:35" relating to the current clip being played.
So I''ll need to somehow figure out how to detect current position and end position. Does anyone know how to do this?
Code so far:
Public Class Form1
Dim Paused As Boolean = False
Dim Started As Boolean = False
Dim PlayedSecond As Boolean = True
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
PlayedSecond = False
AxVLCPlugin21.playlist.items.clear()
AxVLCPlugin21.playlist.add("https://vula.uct.ac.za/access/content/group/fe879ca4-927a-4fca-9cc9-33b12c348b37/vids/Lessig-ItIsAboutTimeGettingOurValuesAroundCopyright522.flv")
AxVLCPlugin21.playlist.play()
Started = True
End Sub
Sub playsecond()
AxVLCPlugin21.playlist.items.clear()
AxVLCPlugin21.playlist.add("http://lsta2011.wikispaces.com/file/view/Rogue%20Waves.mp4")
AxVLCPlugin21.playlist.play()
PlayedSecond = True
Started = False
End Sub
Private Sub AxVLCPlugin21_pause(sender As Object, e As EventArgs) Handles AxVLCPlugin21.pause
Paused = True
End Sub
Private Sub IsFinished_Tick(sender As Object, e As EventArgs) Handles IsFinished.Tick
If Not AxVLCPlugin21.playlist.isPlaying And Paused = False And Started = True And PlayedSecond = False Then
playsecond()
Started = True
End If
End Sub
Private Sub AxVLCPlugin21_play(sender As Object, e As EventArgs) Handles AxVLCPlugin21.play
Paused = False
End Sub
End Class
推荐答案
缺少最新文档会使编程与这些VLC插件是一次发现之旅。我安装了VLC版本''2.0.5 Twoflower',当然还有这个,有用的外观事件前缀为MediaPlayer,例如: MediaPlayerPositionChanged,永远不会被AxVLCPlugin2插件引发。
据我所知,需要轮询,并获取位置/持续时间信息它是输入应该查询的对象。
这个界面在C#
The lack of up to date documentation makes programming with these VLC plugins a voyage of discovery. I have VLC version ''2.0.5 Twoflower'' installed and certainly with this one, the useful looking events prefixed with MediaPlayer, e.g. MediaPlayerPositionChanged, never get raised by the AxVLCPlugin2 plugin.
As far as I can tell, polling is required, and to get position/duration information it''s the input object that should be queried.
This the interface in C#
namespace AXVLC {
public interface IVLCInput {
double fps { get; }
bool hasVout { get; }
double Length { get; }
double Position { get; set; }
double rate { get; set; }
int state { get; }
double Time { get; set; }
}
}
时间给出当前播放位置,长度给出总持续时间,以毫秒为单位。位置是当前位置,缩放0..1(1 = 100%)。
状态属性,可以方便地转换为枚举,具有值范围0..7,即
Time gives the current playback position and Length gives the total duration, both in milliseconds. Position is the current position, scaled 0..1 (1 = 100%).
The state property, which can be conveniently cast to an Enum, has values in the range 0..7, i.e.
Private Enum InputState
IDLE = 0
OPENING = 1
BUFFERING = 2
PLAYING = 3
PAUSED = 4
STOPPING = 5
ENDED = 6
ERRORSTATE = 7
End Enum
我设置了一个间隔为~150ms的计时器,只要AxVLCPlugin2对象存在,它就会连续运行。以下代码将状态信息写入Label控件。
I set up a timer with an interval of ~150ms which runs continuously whenever the AxVLCPlugin2 object exists. The following code will write status information to a Label control.
Dim vlc As AxAXVLC.AxVLCPlugin2
Dim infoTimer as System.Windows.Forms.Timer
Dim status as System.Windows.Forms.Label
Private Sub InfoTimer_Tick(sender As Object, e As EventArgs)
Dim state As InputState = DirectCast(vlc.input.state, InputState)
Select Case state
Case InputState.IDLE, InputState.OPENING, InputState.BUFFERING
status.Text = state.ToString()
Exit Select
Case InputState.PLAYING
Dim title As String = System.IO.Path.GetFileName(vlc.mediaDescription.title)
Dim current As TimeSpan = TimeSpan.FromMilliseconds(vlc.input.Time)
Dim total As TimeSpan = TimeSpan.FromMilliseconds(vlc.input.Length)
Dim pos As Double = vlc.input.Position
status.Text = String.Format("{0} {1} {2}:{3:D2}/{4}:{5:D2} {6:P}", state, title, current.Minutes, current.Seconds, total.Minutes, total.Seconds, pos)
Exit Select
Case InputState.PAUSED
status.Text = String.Format("{0} {1}", state, System.IO.Path.GetFileName(vlc.mediaDescription.title))
Exit Select
Case InputState.STOPPING, InputState.ENDED
status.Text = state.ToString()
Exit Select
Case InputState.ERRORSTATE
status.Text = String.Format("{0} {1}", state, vlc.mediaDescription.title)
Exit Select
Case Else
status.Text = state.ToString()
Exit Select
End Select
End Sub
播放时的输出格式为
播放filename.ext 1:57/18:50 10.35%
希望有一些用途。它全部由C#转换,所以可能会出现一两个错误。
Alan。
Output while playing would be formatted as
PLAYING filename.ext 1:57/18:50 10.35%
Hope that''s of some use. It''s all converted from C# so there may be one or two mistakes.
Alan.
这篇关于如何在vb.net中检测vlc视频播放中的当前位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!