This is a very simple way to show the video file in my program with preservation of aspect ratio.
The only problem I've found is when I do a 2-finger swipe the player stops and I can't get it going again. Oh, and MovieLength() doesn't seem to be accurate and it only plays .mp4 & .m4v movies.
Code:
EnableExplicit
Define event
Define moviefile$
#movieid=1
#moviewnd=2
Define aspectratio.f
If OpenWindow(#moviewnd, 0, 0,200,200, "Play movie", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
Define reduceratio.f
If InitMovie()
moviefile$ = OpenFileRequester("Choose a mp4 file", "", "MP4 Files (*.mp4)", 0)
If Len(moviefile$)=0:End:EndIf
LoadMovie(#movieid,moviefile$)
SetWindowTitle(#moviewnd,GetFilePart(moviefile$)+" ("+FormatDate("%hh:%ii:%ss",MovieLength(#movieid))+")")
;SetWindowTitle(#moviewnd,GetFilePart(moviefile$)+" ("+Str(MovieLength(#movieid))+")")
PlayMovie(#movieid,WindowID(#moviewnd))
ResizeWindow (#moviewnd,WindowX(#moviewnd),WindowY(#moviewnd),MovieWidth(#movieid),MovieHeight(#movieid))
aspectratio=MovieWidth(#movieid)/MovieHeight(#movieid)
If MovieWidth(#movieid)<800
ResizeWindow (#moviewnd,WindowX(#moviewnd),WindowY(#moviewnd),MovieWidth(#movieid),MovieHeight(#movieid))
Else
reduceratio=800/MovieWidth(#movieid)
ResizeWindow(#moviewnd,60,60,MovieWidth(#movieid)*reduceratio,MovieHeight(#movieid)*reduceratio)
ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
EndIf
Else
MessageRequester("Error", "Couldn't initialize movie!")
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_CloseWindow
FreeMovie(#movieid)
End
Case #PB_Event_SizeWindow
;ResizeWindow(#moviewnd,#PB_Ignore,#PB_Ignore,WindowWidth(#moviewnd),WindowHeight(#moviewnd))
;ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowHeight(#moviewnd))
ResizeWindow(#moviewnd,#PB_Ignore,#PB_Ignore,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
ResizeMovie (#movieid ,0,0,WindowWidth(#moviewnd),WindowWidth(#moviewnd)/aspectratio)
EndSelect
ForEver