Encrypted hls playback doesnot happen - ios

I am trying to play a encypted hls content . The contents are chunked using a tool developed locally called chunker .
A catalogue having info about the contents is loaded on the device which wants to play the chunks and is shown as playlist of contents. The catalogue points to the manifest file of each content.
In live scenario, when the chunker is running and chunking the contents, the playback does not start on clicking the playlist, it does not even make a request to the url in d manifest for the decryption key. But the same happens as soon as chunker is stopped .
Exactly similar behaviour happens when trying to play the content using Safari on iPad too.
And now the interesting thing is, this issue doesn't happen with ios simulator or macos and playback is fine but only with iOS device it doesn't play when chunker is running.
Also clear hls content plays just fine on iPad, macos and simulator. No issues with clear content anywhere.
I used iOS 8.2 & 9 iPad and i used Avplayer as player.
Can anybody give me any clue on this ?
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"Trying to play media ");
NSURL *mediaUrl = [[NSURL alloc]initWithString:[[self.arrMedialist objectAtIndex:indexPath.row]objectForKey:#"url"]];
// NSURL *mediaUrl = [[NSURL alloc]initWithString:#"http://10.237.166.59/ccad/hls.m3u8"];
AVPlayer *player = [[AVPlayer alloc]initWithURL:mediaUrl];
AVPlayerViewController *controller = [[AVPlayerViewController alloc]init];
controller.player = player;
controller.showsPlaybackControls = YES;
[self presentViewController:controller animated:YES completion:nil];
NSLog(#"playing media url %# ", mediaUrl);
[player play];
}

Finally figured out what was the problem. Interesting one though, might help others.
For every chunk our chunker was adding an EXT-X-KEY tag for key uri first and the chunk tag or name would get appended just before processing the next chunk, so at anytime the playlist would end with EXT-X-KEY tag . The actual chunk that was corresponding to this tag will be added only after the chunk is created and then again quickly followed by EXT-X-KEY tag for the next chunk. It looks like the player thinks that it read the playlist in the middle of an update (since the chunk for the last EXT-X-KEY tag is not yet updated) and keep trying. When we stop the chunker, the signal is catched and playlist is updated with the last chunk. So, after stopping the player is able to play.
And strangely, only iOS has this problem, macos and simulator seem to have handled this case.

Related

AVPlayerViewController stuck on first frame of local video

In one of my ViewControllers, I have an AVPlayerViewController. In my viewDidLoad I have
self.videoPlayerController = [AVPlayerViewController new];
Then, I play a video using the following method
- (void)playVideo:(NSURL*)videoURL {
[self presentViewController:self.videoPlayerController animated:YES completion:^(){
AVPlayer *player = [[AVPlayer alloc] initWithURL:videoURL];
[self.videoPlayerController setVideoGravity:AVLayerVideoGravityResizeAspect];
[self.videoPlayerController setPlayer:player];
[self.videoPlayerController.player play];
}];
}
When playing a video for the first time, the AVPlayerViewController appears, but the video is stuck on the first frame, and will not play. No audio plays either.
In iOS 10.0, the seekbar in the on screen controls show that the video is playing (it will progress to the end). In iOS 10.2 however, the seekbar is stuck at 0:00 as well.
I am experiencing this problem on iPads with iOS versions 10.0 and 10.2, however, it works in the XCode simulator (both 10.0 and 10.2).
My problem is similar in nature to this.
Also, the video plays correctly if you close the ViewController containing the AVPlayerViewController, reopen it, and attempt to play the video again.
I guess that the problem is in your video file. Try to download another video mp4 video sample. Add it to your project and try.

buffer video before playing it on iphone

I'm doing some testing which during I would like to:
- Take a video that is in the app folder
- load that video to memory (buffer it)
- play the bufferd frames from the memory
All made on iPhone
Actually,
I would like to play a video from memory.
(I also want to load the video to memory by frames).
I hope it clear enough.
How can I accomplish this?
Tnx
EDIT:
Maybe I can point my question a little more..
I have a server that streams video via UDP (let's say that for the simuloation I'm using VLC to stream via UDP).
What do I have to do and implement in order to get the UDP stream from VLC and display it on the screen of my I device (of course i'm talking about writing code and not using VLC streamer :-) ).
Hope that's better and that I'll get some answers now.
Tnx
A video has to be buffered only if you receive the video from a server over internet via packets/Streams.
Else you can just play the video using below code:-
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"yourVideo" ofType:#"yourVideoType" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]];
[self.view addSubview:[player view]];
[player play];
[player release];
You can implement the notification MPMoviePlayerLoadStateDidChangeNotification, if you are playing the videos after fetching over some data service.(GPRS,2G, Internet.)

Streaming audio and video into IOS app

I am creating an iPhone app on Xcode with build in video and music, the trouble is I want to keep the whole app below 20MB
I've compressed the videos to a OK standard but I'm still over the 20MB
Is there a way I can just stream the videos from a server, so when I click on my video / Audio button in the app it plays like it was saved within the app.
Many Thanks
Try this:
MPMoviePlayerViewController *movieView = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:#"http://movieurl"]];
[self presentMoviePlayerViewControllerAnimated:movieView];
don't forget to import MediaPlayerFramework
If you need more control over streaming, playback or the view itself, see MPMoviePlayerController Class Reference

MPMoviePlayerController Audio show "Done" Button

I use the MPMoviePlayerController to Play an Audio Stream.
My code follows the example at:
http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html
Everything works fine, but while the stream is playing there is no "done"
button to close the Player.
I tested it first with a normal .mp3 file. With the file the only
possibility I found is to skip to the end,
so the player gets the MPMoviePlayerPlaybackDidFinishNotification
notification
(but this won't work on an endless stream, since there is no timeline to
skip to the end).
I tried various styles like [mp setControlStyle:MPMovieControlStyleFullscreen]; with no succes.
In the documentation at
MPMoviePlayerController Class stands:
This class plays any movie or audio
file supported in iOS. This includes
both streamed content and fixed-length
files
Is there a possibility to display that button while playing some audio
content, or has anyone another solution?
I tried to show you an screenshot but "new users can only post a maximum of two hyperlinks".
i found a solution by my self.
Using the MPMoviePlayerViewController class, instead of MPMoviePlayerController solved the problem:
NSString *path = #"http://yourstreamingurl.com/stream.m3u";
MPMoviePlayerViewController* mpviewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:path]];
mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentModalViewController:mpviewController animated:YES];
[[mpviewController moviePlayer] play];
For playing file locally, remove
mpviewController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Other wise it will return
Terminating app due to uncaught exception NSInvalidArgumentException reason An AVPlayerItem cannot be associated with more than one instance of AVPlayer

prevent MPMoviePlayerController from automatically playing in iOS 4.2.1

I have an MPMoviePlayerController where I load a video from a URL. In iOS 3.2.2 the video started downloading when I added it to a view, but it didn't play until I hit the play button (which is what I want). However, since iOS 4.2.1 came out, it started behaving differently; the video starts downloading and plays automatically.
Here's how I load my MPMoviePlayerController:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:theVideo.fileUrl]];
player.view.frame = articleVideoFrame;
[mainView addSubview:player.view];
I even tried to perform a [player pause]; after the addSubview part, but it still plays automatically. Could you guys help me with this one?
Got it! I used player.shouldAutoplay = NO; and that did the trick. Documentation says it is by default YES, which explains it all. Probably in 3.2 default was NO, but has been switched in 4.2.
I have noticed some other behavior changes in video playback in 4.2.1...namely the video player does not become visible until it starts receiving the data for the movie...
In the previous versions it used to come up instantaneously with "Loading movie..." text on top.
Sometimes, the player gets stuck in when not in full screen mode, with no Done button available or not responding to touches on Pause and Zoom...
I am having other more subtle issues with the playback but I can't isolate the issue just yet...

Resources