The class MPMoviePlayerController has the major drawback of not adequately handle multiple concurrent video, in addition to making it difficult to create a sequence of video one after another. che è una sottoclasse di AVPlayer ), appartenente al framework più a basso livello AVFoundation , è invece estremamente più versatile, nonostante mantenga egualmente una semplicità nell'implementazione. The class AVPlayer (or AVQueuePlayer which is a subclass of AVPlayer ), belonging to the framework lowest level AVFoundation , is instead extremely versatile, despite maintaining also a simplicity in implementation.

Let me show you how simple it is to play two videos in sequence:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | / / Insert the framework AVFoundation # Import <AVFoundation/AVFoundation.h> ... / / Definition AVQueuePlayer * AVPlayer; AVPlayerItem * avPlayerItemOne; AVPlayerItem * avPlayerItemTwo; ... / / Initialize video sequences void ) initAndPlayMovie - (Void) initAndPlayMovie { AVPlayerItem alloc ] initWithURL : avPlayerItemOne = [[AVPlayerItem alloc] initWithURL: fileURLWithPath : [ NSURL fileURLWithPath: mainBundle ] pathForResource : @ "movie1" ofType : @ "mp4" ] ] ] ; [[ NSBundle mainBundle] pathForResource: @ "movie1" oftype: @ "mp4"]]]; AVPlayerItem alloc ] initWithURL : avPlayerItemTwo = [[AVPlayerItem alloc] initWithURL: fileURLWithPath : [ NSURL fileURLWithPath: mainBundle ] pathForResource : @ "movie2" ofType : @ "mov" ] ] ] ; [[ NSBundle mainBundle] pathForResource: @ "movie2" oftype: @ "mov"]]]; playerItems = [ [ NSArray alloc ] initWithObjects : avPlayerItemOne, avPlayerItemTwo, nil ] ; NSArray * playerItems = [[ NSArray alloc] initWithObjects: avPlayerItemOne, avPlayerItemTwo, nil]; AVQueuePlayer alloc ] initWithItems : playerItems ] ; AVPlayer = [[AVQueuePlayer alloc] initWithItems: playerItems]; ; [PlayerItems release]; [ AVPlayerLayer playerLayerWithPlayer : avPlayer ] ; AVPlayerLayer avPlayerLayer * = [AVPlayerLayer playerLayerWithPlayer: AVPlayer]; CGRectMake ( 0 , 0 , 1024 ., 768 . ) ] ; [AvPlayerLayer setFrame: CGRectMake (0, 0, 1024., 768.)]; avPlayerLayer ] ; [Self.view.layer addSublayer: avPlayerLayer]; ; [AVPlayer play]; avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; defaultCenter ] addObserver : self selector : @selector ( playerItemDidReachEnd : ) name : AVPlayerItemDidPlayToEndTimeNotification object : [ avPlayer currentItem ] ] ; [[ NSNotificationCenter defaultCenter] addObserver: self selector: @ selector (playerItemDidReachEnd:) name: AVPlayerItemDidPlayToEndTimeNotification object: [AVPlayer CurrentItem]]; } ... / / Notify when finished movie ... step to possimo void ) playerItemDidReachEnd : ( NSNotification * ) notification - (Void) playerItemDidReachEnd: ( NSNotification *) notification { ; [AVPlayer advanceToNextItem]; } |










There are no comments for this post
Leave a comment