Primitive Video Player

Share your advanced PureBasic knowledge/code with the community.
chris319
Enthusiast
Enthusiast
Posts: 782
Joined: Mon Oct 24, 2005 1:05 pm

Primitive Video Player

Post by chris319 »

I need to be able to play videos and keep track of the location of the play head in frames, so I came up with this. Eventually a frame counter will be added.

Suggestions for improvements invited. I may not have the frame rate exactly right but it's close.

Code: Select all

If InitMovie() = 0
  MessageRequester("Error", "Can't initialize movie playback!", 0) 
  End
EndIf

;MovieName$ = OpenFileRequester("Choose the movie to play", "", "Movie files|*.avi;*.mpg;*.mp4;*.mkv|All Files|*.*", 0)
movieName$ = "D:\Videos\Interpositives\Short.avi"

Global frameCount = 0

If MovieName$
  If LoadMovie(1, MovieName$)
  
;Global framedur.d = (1/29.97) * 1000
If MovieInfo(1,0) = 29: fps = 29.97: ElseIf MovieInfo(1,0) = 59: fps = 59.94:EndIf
Global framedur.d = 1/fps * 1000

OpenWindow(1, 100, 150, MovieWidth(1), MovieHeight(1), "PureBasic - Movie")
    PlayMovie(1, WindowID(1))
    
For ct = 1 To 1000
PauseMovie(1) : Delay(frameDur)
frameCount + 1:MovieSeek(1,frameCount)
ResumeMovie(1)
Next

PauseMovie(1)

    Repeat
    Until WaitWindowEvent() = #PB_Event_CloseWindow
  Else
    MessageRequester("Error", "Can't load the movie...", 0)
  EndIf
EndIf