How to detect the end of a video?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am
Location: Albany, Western Australia

How to detect the end of a video?

Post by grovecat » Thu May 09, 2013 10:37 am

I create a native video player in code and give it a path to a video on the camera roll (using the mergAV external). Then via a transparent button over the screen I can either use the button to toggle pause and play, or set it to stop the video. When I stop it this way, my code deletes the player and returns to another card. So far so good.

The problem is that when the video ends naturally it just hangs on the last image and I want it do the same as when it is stopped as above. And I can't work out how to accomplish that small task. I thought I may be able to obtain the duration from a mobileControlGet property, and use a Send message based on that time, but both playableDuration and endTime return zero.

So how can I determine when a video ends naturally?

TIA
Don

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: How to detect the end of a video?

Post by Simon » Thu May 09, 2013 1:42 pm

Check out "playerFinished" in the dictionary.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Martin Koob
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 237
Joined: Sun May 27, 2007 8:19 pm

Re: How to detect the end of a video?

Post by Martin Koob » Thu May 09, 2013 5:56 pm

DId you try the message AVPlayerItemDidPlayToEndTimeNotification?

put a handler for this in the control that you used to create the AVPlayer with a parameter for the Player pointer.

Martin

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am
Location: Albany, Western Australia

Re: How to detect the end of a video?

Post by grovecat » Fri May 10, 2013 1:33 am

Thanks guys

The playerFinished message does the job nicely.

I can't use the AVPlayerItemDidPlayToEndTimeNotification, which relates the mergAV player. I'm only using mergAV to get the path to the video, which I then pass to the native iOS player.

Cheers
Don

grovecat
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 99
Joined: Thu Aug 04, 2011 10:32 am
Location: Albany, Western Australia

Re: How to detect the end of a video?

Post by grovecat » Fri May 10, 2013 4:56 am

Perhaps I should explain why I use mergAV to pick the video and then use a native player rather than the mergAVPlayer. The reason is that in this case I am picking a video from the camera roll, and that path can't be played by the mergAVPlayer but the native iOS player can handle it.

Don

Post Reply

Return to “iOS Deployment”