Pourquoi ce code Objective-C ne lira pas une video AVPlayerViewController?

entrez la description de l'image ici Les deux sont dans viewDidLoad (). Quel est le problème avec ce file source objective-c? La version rapide fonctionne comme un charme … Xcode ver. 8.2 iOS 10

Swift (OK):

let path : Ssortingng = Bundle.main.path(forResource: "charlie", ofType: "mp4")! let movieurl : URL = URL(fileURLWithPath: path) let movie : AVPlayerViewController = AVPlayerViewController() movie.view.frame = self.view.bounds let player : AVPlayer = AVPlayer(url: movieurl) movie.player = player self.view.addSubview(movie.view) player.play() 

Objective-C (Ne pas afficher / lire la video):

  AVPlayerViewController* movie; AVPlayer* player; NSSsortingng *path = [[NSBundle mainBundle] pathForResource:@"charlie" ofType:@"mp4"]; NSURL *url = [NSURL URLWithSsortingng:path] ; movie = [[AVPlayerViewController alloc] init]; movie.view.frame = self.view.bounds; player = [[AVPlayer alloc] initWithURL:url]; [movie setPlayer:player]; [self.view addSubview:movie.view]; [player play]; 

 @import AVKit; @import AVFoundation; @property (nonatomic) AVPlayer *avPlayer; @property (nonatomic) AVPlayerViewController* avPlayerView; NSSsortingng *path = [[NSBundle mainBundle] pathForResource:@"Video1" ofType:@"mp4"]; NSURL *url = [[NSURL alloc] initFileURLWithPath: path]; AVAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset]; avPlayer = [AVPlayer playerWithPlayerItem:anItem]; [avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil]; self.avPlayerView = [[AVPlayerViewController alloc] init]; self.avPlayerView.view.frame = self.view.bounds; [self.avPlayerView setPlayer:_avPlayer]; [self.view addSubview:_avPlayerView.view]; - (void)observeValueForKeyPath:(NSSsortingng *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (object == avPlayer && [keyPath isEqualToSsortingng:@"status"]) { if (avPlayer.status == AVPlayerStatusFailed) { NSLog(@"AVPlayer Failed"); } else if (avPlayer.status == AVPlayerStatusReadyToPlay) { NSLog(@"AVPlayer Ready to Play"); } else if (avPlayer.status == AVPlayerItemStatusUnknown) { NSLog(@"AVPlayer Unknown"); } } } -(IBAction) BtnPlay:(id)sender { [avPlayer play]; } -(IBAction) BtnPause:(id)sender { [avPlayer pause]; } 

Essayez mon code. si un problème avec mon code mettre un commentaire. Je vous remercie. Codage heureux.

NSSsortingng * path = [[NSBundle mainBundle] pathForResource: @ "charlie" deType: @ "mp4"];

Essayer

En utilisant [ NSURL fileURLWithPath : path] au lieu de [ NSURL URLWithSsortingng : path]

[NSURL fileURLWithPath]

Ou

[[NSBundle mainBundle] URLForResource: @ "charlie" avecExtension: @ "mp4"]