La classe MPMoviePlayerController ha il grosso difetto di non gestire adeguatamente più video contemporanei, oltre a rendere difficile creare una sequenza di video uno dopo l’altro. La classe AVPlayer (o AVQueuePlayer che è una sottoclasse di AVPlayer), appartenente al framework più a basso livello AVFoundation, è invece estremamente più versatile, nonostante mantenga egualmente una semplicità nell’implementazione.

Lasciatemi mostrare come sia semplice riprodurre due video in sequenza:
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 | // Inserite il framework AVFoundation #import <AVFoundation/AVFoundation.h> ... // Definizione AVQueuePlayer *avPlayer; AVPlayerItem *avPlayerItemOne; AVPlayerItem *avPlayerItemTwo; ... // Inizializza sequenze video - (void)initAndPlayMovie { avPlayerItemOne = [[AVPlayerItem alloc] initWithURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"movie1" ofType:@"mp4"]]]; avPlayerItemTwo = [[AVPlayerItem alloc] initWithURL: [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:@"movie2" ofType:@"mov"]]]; NSArray *playerItems = [[NSArray alloc] initWithObjects:avPlayerItemOne, avPlayerItemTwo, nil]; avPlayer = [[AVQueuePlayer alloc] initWithItems:playerItems]; [playerItems release]; AVPlayerLayer *avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer]; [avPlayerLayer setFrame:CGRectMake(0, 0, 1024., 768.)]; [self.view.layer addSublayer:avPlayerLayer]; [avPlayer play]; avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidReachEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:[avPlayer currentItem]]; } ... // Notifica fine filmato... passo al possimo - (void)playerItemDidReachEnd:(NSNotification *)notification { [avPlayer advanceToNextItem]; } |








4
Non ci sono commenti per questo Post
Lascia un commento