Click here to Skip to main content
12,355,505 members (71,936 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET media VS2012
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
Posted 27-Jan-13 1:43am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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; }
  }
}
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

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

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.
  Permalink  
Comments
Andrew Smith 27-Jan-13 11:15am
   
Thank you
idahar 8-Jul-15 8:56am
   
Thanks yar (Dude)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100