'IOS AVPlayer is not playing http urls
I'm trying to play videos with AVPlayer using URL's in IOS 10. Videos are playing fine with HTTPS URL but, with HTTP i'm getting blank screen. I also allowed NSArbitrary Loads in plist.
Please suggest, is AV Player doesn't support HTTP or any mistakes from my side?
Here's the code i'm using
NSURL * url = [NSURL URLWithString:@"http://some_ip_addr/SampleVideo.mp4"];
objPlayerItem = [AVPlayerItem playerItemWithURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:objPlayerItem];
AVPlayer *player = [[AVPlayer alloc]initWithPlayerItem:objPlayerItem];
AVPlayerLayer * playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
playerLayer.frame = self.view.frame;
[self.view.layer addSublayer:playerLayer];
[player play];
Solution 1:[1]
This question is old, but today I as well have the same situation. AVPlayer plays video in this way:
- (IBAction)videoButtonPressed:(id)sender {
NSURL *videoUrl = [[NSURL alloc]initWithString:@"http://clips.vorwaerts-gmbh.de/VfE_html5.mp4"];
AVAsset *asset = [AVURLAsset URLAssetWithURL:videoUrl options:nil];
AVPlayerItem *anItem = [AVPlayerItem playerItemWithAsset:asset];
self.avPlayer = [AVPlayer playerWithPlayerItem:anItem];
[self.avPlayer addObserver:self forKeyPath:@"status" options:0 context:nil];
self.avPlayerView = [[AVPlayerViewController alloc]init];
self.avPlayerView.player = self.avPlayer;
self.avPlayerView.view.frame = self.view.bounds;
[self.view addSubview:self.avPlayerView.view];
[self.avPlayer play];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
if (object == self.avPlayer && [keyPath isEqualToString:@"status"]) {
if (self.avPlayer.status == AVPlayerStatusFailed) {
NSLog(@"AVPlayer Failed");
} else if (self.avPlayer.status == AVPlayerStatusReadyToPlay) {
NSLog(@"AVPlayer Ready to Play");
} else if (self.avPlayer.status == AVPlayerItemStatusUnknown) {
NSLog(@"AVPlayer Unknown");
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Melany |
