- Home /
How To Loop FullScreen Video On IOS
Hello, Thank you very much for your time and wisdom! I am trying to loop a fullscreen video on IOS indefinitely, and only close the video once a user has touched the screen. I got the movie to play fine and cancel on input, but there doesn't seem to be any documentation on making the video loop. The default behavior is for it to just play once and close automatically.
I'm using: PlayFullScreenMovie(path, Color, FullScreenMovieControlMode.CancelOnInput)
How can I implementing a looping movie on IOS?
Hi pajamajama :)
Did you ever figure out a solution to this problem? I need the same functionality.
I did. It's quite complicated and involves augmenting the xcode project. When I have a little more time tonight I'll write up some instructions.
Yes. Writing it up now. Sorry, been very busy with work.
Answer by pajamajama · Oct 24, 2013 at 03:39 AM
My solution may be a little long winded. Would love to see some more straightforward code, Objective-C really confuses me so I had to do a lot of trial and error. Also to my knowledge there is no way to do this yet within Unity. It needs to be done inside Xcode project.
This solution also removes the sliding animation for when the movie file comes up.
Get JRSwizzle.h and JRSwizzle.m from github. Place both files in your Classes folder inside the Xcode project.
Generate a file called UIViewController.h and place it in the Classes folder as well. Put the following code in UIViewController.h
#import "JRSwizzle.h" #import "VideoViewController.h" @interface UIViewController(OverrideAnimatedTransition) - (void) nonanimatedPresentMoviePlayerViewControllerAnimated (MPMoviePlayerViewController*) moviePlayerViewController; - (void) nonanimatedDismissMoviePlayerViewControllerAnimated; @end @implementation UIViewController(OverrideAnimatedTransition) - (void) nonanimatedPresentMoviePlayerViewControllerAnimated:(MPMoviePlayerViewController*) moviePlayerViewController { [self presentModalViewController:moviePlayerViewController animated:NO]; } - (void) nonanimatedDismissMoviePlayerViewControllerAnimated { [self dismissModalViewControllerAnimated:NO]; } @end
Locate the class AppController.mm and put the following code inside "didFinishLaunchingWithOptions():"
NSError* err = nil; [UIViewController jr_swizzleMethod:@selector(presentMoviePlayerViewControllerAnimated:) withMethod:@selector(nonanimatedPresentMoviePlayerViewControllerAnimated:) error:&err]; [UIViewController jr_swizzleMethod:@selector(dismissMoviePlayerViewControllerAnimated) withMethod:@selector(nonanimatedDismissMoviePlayerViewControllerAnimated) error:&err];
and put these two lines at the top of AppController.mm
#import "JRSwizzle.h"
#import "UIViewController.h"
That should work! Good Luck!
The line below is responsible for looping the video. It's in the UIViewController.h code above.
moviePlayerViewController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
Answer by leothener · Jan 29, 2017 at 09:41 AM
PlayFullScreenMovie is actually implemented in FullScreenVideoPlayer.mm under iOS project.
There are 2 classes to consider:
AVKitVideoPlayback
Inside actuallyStartTheMovie:(NSURL*)url function add:
videoViewController.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[videoViewController.player currentItem]];
Under onPlayerDidFinishPlayingVideo function:
remove [self finish];
Under - (void)finish
[[NSNotificationCenter defaultCenter] removeObserver:self
name:AVPlayerItemDidPlayToEndTimeNotification
object:[videoViewController.player currentItem]];
Add new function:
- (void)playerItemDidReachEnd:(NSNotification *)notification
{
AVPlayerItem *p = [notification object];
[p seekToTime:kCMTimeZero];
[videoViewController.player play];
}
MPVideoPlayback (for old iOS)
Under - (void)actuallyStartTheMovie:(NSURL*)url function
moviePlayer.repeatMode = MPMovieRepeatModeOne;
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How to play the movie without a seek bar on iOS8& avoid crashing on iOS5 devices? 0 Answers
How to tilt the gameobject based of Input.Acceleration? 0 Answers
Facebook unity sdk: is it possible to send friend invites/app requests to non app users ? 1 Answer