I would like to implement live streaming in iOS app, i found some suggestions to convert and play already recorded videos, but i need to implement direct live streaming video from iPhone/Webcam to iOS App.
How to convert webcam/iPhone or any other recording video to .M3U8?, How to send this video to Server?
Please give me some suggestions and tutorials. Thanks
use MPMoviePlayerController
NSURL *mediaURL = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
For youtube streams, you can use youtube-ios-player-helper lib.
https://github.com/youtube/youtube-ios-player-helper
Related
i m able to play Live Streaming Video in iOS using following code :
NSURL *mediaURL = [NSURL URLWithString:#"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:mediaURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mp.view.frame = self.view.bounds;
[mp setControlStyle:MPMovieControlStyleFullscreen];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
//[mp setFullscreen:YES];
[self.view addSubview:[mp view]];
[mp prepareToPlay];
[mp play];
what i m passing is .m3u8 file format url to the MPMoviePlayerController, and i m able to play Live Streaming. but how can i achieve it using Kaltura's Live Streaming ?
according to http://corp.kaltura.com/company/news/press-release/kaltura-%E2%80%98cracks-code%E2%80%99-reliable-hls-video-streaming-android-devices there is Android SDK for live streaming of videos using Kaltura, is there any iOS Kaltura SDK for Live Streaming ? or Do i have to use iOS built in MPMoviePlayerController for Live Streaming , if yes then what is the way ?
Please Help.
In order to play Kaltura live streaming you just need to grab the manifest url with the following params:
/format/applehttp/protocol/http/a.m3u8
more details here:
http://knowledge.kaltura.com/faq/how-retrieve-download-or-streaming-url-using-api-calls
I would like to loop a mp4 file in UIWebView.
e.g.
If you go to this link (http://techslides.com/demos/sample-videos/small.mp4) to open UIWebView, you won't be able to play it in loop. But I would like to watch this mp4 video for loop and loop again.
Please give me any tips to overcome!
Cheers,
You can simply use MPMoviePlayerController with setRepeatMode:MPMovieRepeatModeOne.
This should allow seamless looping of any video, and it's simple to implement.
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Your Cool Video File" ofType:#"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;
[playerController.moviePlayer play];
Important to remember to subscribe to the end playback notification like so:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
Start playback manually in moviePlayBackDidFinished method
I have a AVPlayer that plays video from remote url.
Here is my code:
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:videoUrl];
self.player = [AVPlayer playerWithPlayerItem:playerItem];
self.player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
playerLayer.frame = playerView.bounds;
[playerView.layer addSublayer:playerLayer];
[self.player play];
When I start to stream I have only less then a second video chunck and then downloading stops and nothing happens.
MPMoviePlayerController and browser plays this video as usual.
I also doubt, that it might be effect of cropping video (because videos without cropping works fine). Here is the guide I use to crod video http://www.one-dreamer.com/cropping-video-square-like-vine-instagram-xcode/
Also clean app with same setup can't play video.
Any ideas? thanks!
Use the AVPlayerItemPlaybackStalledNotification
[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemPlaybackStalledNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
[weakself performBlockOnMainQueueAfterDelay:1.5 block:^{
[weakself.player play];
}];
}];
I'm using this code to try and play a video. However the video is never played, the call back is never made to say it's finished. I can't see anything that I'm missing or have where it shouldn't be. I've checked the path and that's fine. The video playback view does appear. It just doesn't play at that point.
Any suggestions?
NSURL *movieURL = [[NSBundle mainBundle] URLForResource:#"IntroMovie" withExtension:#"mov"];
NSLog(#"%#", movieURL);
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(playbackFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerController];
[moviePlayerController prepareToPlay];
[moviePlayerController.view setFrame:self.view.bounds];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
The problem lies within the fact, that your moviePlayerController is being cleaned up due to ARC.
Try if it helps to introduce a strong property for the MPMoviePlayerController.
I want to Download and Streaming and Downloading the video simulteniouslly by App.
There video are heavy so Converted into m4u8 format and using the VOD Live streaming cocept to play them in MPMoviePlayer.
How to download there live streaming Video simulteniouslly with palying .
Can you suggest me.
FOllowing are the code to play the movie, Hope this is useful..
NSURL *fileURL = [NSURL URLWithString:#"<Video URL>"];
[self playMovie:fileURL];
-(IBAction)playMovie:(NSString *) theURL
{
NSURL *fileURL = [NSURL fileURLWithPath:theURL];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.useApplicationAudioSession = NO;
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
[moviePlayerController release];
}
To Make the Video capable of streaming
Video should be of .mp4 format.
All videos should be converted using the Miro Video Converter in Mac (Or similar converters) and make it compatible to play in iPhone, iPad and Android devices.
Converted videos will play in mobile devices. However, the video will play only after the full video is downloaded from the server.
To make the video streaming, the video's metadata has to be moved to the beginning of the video. To achieve this, we have to use a tool called Medadata mover to encode the video.
Then the final video is compatible of streaming and able to play in all mobile devices.
Then the video have to be FTP'ed to the desired web hosting. for example demo.com/videos/test.mp4.
Then the video can be configured in iPhone or android app and can be streamed.
See More for Apple Live Streaming
HTTP LIve Streaming