Looping video
Looping video
So, I'm trying to do some actual programming now, as apposed to just using the Designer. And I want a video to play continuously until the mouse is clicked.
There doesn't seem there is a flag option for looping a video, unless I've completely missed it.
So, how can this be achieved?
There doesn't seem there is a flag option for looping a video, unless I've completely missed it.
So, how can this be achieved?
Re: Looping video
So, I tried to fix it myself, but with my lack of expertise I can't get it to work.
Some lines are commented out to test what happened. But either the video just stops, or the application ends with an error that it can't find the video file.
Eventually I'd like the video to loop continuously on a layer with with things happening on a higher layer.
Code: Select all
@VERSION 8,0
@REQUIRE "avcodec", {Link = True}
@DISPLAY{WIDTH = 960, HEIGHT = 540, MODE = "WINDOWED", TITLE = "Looping Video"}
@VIDEO 1, "Seamless.mp4"
r = 0
While r < 10 And IsVideoPlaying(1) = False
;OpenVideo(1, "Seamless.mp4")
SeekVideo(1, 0)
PlayVideo(1)
r = r + 1
Wait (200)
;CloseVideo(1)
Wend
WaitLeftMouse
End
Eventually I'd like the video to loop continuously on a layer with with things happening on a higher layer.
- airsoftsoftwair
- Posts: 5425
- Joined: Fri Feb 12, 2010 2:33 pm
- Location: Germany
- Contact:
Re: Looping video
Don't use a polling loop. Install an event handler that listens to "OnVideoEnd" using InstallEventHandler() and then call PlayVideo() whenever that event handler triggers. Take a look at the "VideoPlayer" example that comes with Hollywood. It shows how to listen to "OnVideoEnd" (it will reset the seek bar to 0 when video playback has finished).
- Juan Carlos
- Posts: 884
- Joined: Mon Sep 06, 2010 1:02 pm
Re: Looping video
Try this:
Code: Select all
Function p_ShowVideo()
PlayVideo(1, #CENTER, #CENTER)
SetInterval(1, p_CheckVideoIntro, 25) ;Checking if the video is playing currently.
EndFunction
Function p_CheckVideoIntro()
playing=IsVideoPlaying(1)
If playing=False
CloseVideo(1) ;Close the video.
ClearInterval(1)
p_MainFunction() ;Jump to other function when the video has finish.
EndIf
EndFunction
Re: Looping video
I ended up using Designer which works. Except video playback (even Anims) are slow as molasses on my Amikit setup.Juan Carlos wrote: ↑Mon Aug 24, 2020 12:12 pm Try this:Code: Select all
Function p_ShowVideo() PlayVideo(1, #CENTER, #CENTER) SetInterval(1, p_CheckVideoIntro, 25) ;Checking if the video is playing currently. EndFunction Function p_CheckVideoIntro() playing=IsVideoPlaying(1) If playing=False CloseVideo(1) ;Close the video. ClearInterval(1) p_MainFunction() ;Jump to other function when the video has finish. EndIf EndFunction
Could you please check the code and see what I'm doing wrong, because the video only plays once and then freezes on the last frame.
Code: Select all
@VERSION 8,0
@REQUIRE "avcodec", {Link = True}
@DISPLAY{WIDTH = 960, HEIGHT = 540, MODE = "WINDOWED", TITLE = "Femme Fatale"}
EscapeQuit(True)
SetMusicVolume(1, 32)
@VIDEO 1, "Seamless.avi"
@MUSIC 1, "FemmeFatale.mp3"
Function p_ShowVideo()
PlayVideo(1)
SetInterval(1, p_CheckVideoIntro, 25) ;Checking if the video is playing currently.
DebugPrint("p_ShowVideo")
EndFunction
Function p_CheckVideoIntro()
playing=IsVideoPlaying(1)
If playing=False
CloseVideo(1) ;Close the video.
ClearInterval(1)
p_MainFunction() ;Jump to other function when the video has finish.
DebugPrint("p_CheckVideoIntro")
EndIf
EndFunction
p_ShowVideo()
p_CheckVideoIntro()
WaitLeftMouse
End
- Juan Carlos
- Posts: 884
- Joined: Mon Sep 06, 2010 1:02 pm
Re: Looping video
The problem is that you have active the two functions, you have only p_ShowVideo(), the p_CheckVideoIntro() remove it because it cause the problem, Hollywood try to run the two functions at the same time and only is possible one, besides p_CheckVideoIntro() is call for the p_ShowVideo().
Other problem is the speed playing videos, you have think the codec and the video size because if you run the demo with 68k real or emulated the speed is slow, you have one video with an old codec and with a little size, because Hollywood requires too much CPU to play it, for test the video with Hollywood you can use the VAMP Player for you get one test the videos that play fine ir not.
The PlayVideo instruction play the video once, for loop you have recall the p_VideoShow() function.
Other problem is the speed playing videos, you have think the codec and the video size because if you run the demo with 68k real or emulated the speed is slow, you have one video with an old codec and with a little size, because Hollywood requires too much CPU to play it, for test the video with Hollywood you can use the VAMP Player for you get one test the videos that play fine ir not.
The PlayVideo instruction play the video once, for loop you have recall the p_VideoShow() function.
Re: Looping video
Unfortunately removing that line makes no difference. It still plays once and freezes.
I only left the line in there because I was testing to see if it would work differently.
I only left the line in there because I was testing to see if it would work differently.
- Juan Carlos
- Posts: 884
- Joined: Mon Sep 06, 2010 1:02 pm
Re: Looping video
The video play only once but the problem the freeze the last frame you can use the Cls() to clean the window and remove the last video frame. To repeat the code un loop I'll try to make a Code.
- Juan Carlos
- Posts: 884
- Joined: Mon Sep 06, 2010 1:02 pm
Re: Looping video
Try this:
And this other code with InstallEventHandler({OnVideoEnd}):
Code: Select all
;To the program ask the plugins to play the video and music formats.
@REQUIRE "oggvorbis"
@REQUIRE "avcodec"
@VIDEO 1, "Videos/RomBoot3-0.mp4"
@MUSIC 1, "Melodias/TheCrackSong01.ogg"
Function p_IntroVideo()
PlayMusic(1, 1) ;1 to infinite times, 0 to once.
PlayVideo(1, #CENTER, #CENTER)
SetInterval(1, p_CheckVideoIntro, 25) ;Check video is playing.
EndFunction
Function p_CheckVideoIntro()
playing=IsVideoPlaying(1)
If playing=False
;This to play the video once:
;CloseVideo(1) ;Close video.
;ClearInterval(1) ;Finish the Interval.
;StopMusic(1) ;Stop the background song when the video is finish.
;p_Main()
;This to play the video in loop:
p_IntroVideo() ;Here the program goes to p_IntroVideo() to play it in loop.
EndIf
EndFunction
Function p_Main()
Cls()
TextOut(#CENTER, #CENTER, "Hello World!")
EndFunction
;Main function to run this program.
p_IntroVideo()
EscapeQuit(True)
Repeat
WaitEvent
Forever
Code: Select all
;To the program ask the plugins to play the video and music formats.
@REQUIRE "oggvorbis"
@REQUIRE "avcodec"
@VIDEO 1, "Videos/RomBoot3-0.mp4"
@MUSIC 1, "Melodias/TheCrackSong01.ogg"
Function p_IntroVideo()
PlayMusic(1, 1) ;1 to infinite times, 0 to once.
PlayVideo(1, #CENTER, #CENTER)
EndFunction
Function p_Main()
;This to play the video once:
CloseVideo(1) ;Close video.
StopMusic(1) ;Stop the background song when the video is finish.
TextOut(#CENTER, #CENTER, "Hello World!")
;This to play the video in loop:
;p_IntroVideo() ;Here the program goes to p_IntroVideo() to play it in loop.
EndFunction
;Main function to run this program.
p_IntroVideo()
InstallEventHandler({OnVideoEnd=p_Main})
EscapeQuit(True)
Repeat
WaitEvent
Forever
Re: Looping video
Thanks for taking the time to help out. I appreciate it.
Your code works as far as getting it to loop. But the music restarts as soon as the video restarts. If I recall correctly there should be a way to set them to play asynchronously. Also, there is a frame of black background before the video restarts. Not sure how to fix that.
Your code works as far as getting it to loop. But the music restarts as soon as the video restarts. If I recall correctly there should be a way to set them to play asynchronously. Also, there is a frame of black background before the video restarts. Not sure how to fix that.