Streaming audio and video into IOS app - ios

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

Related

AVPlayerViewController video's audio background playing and support for multiple formats

I have to do a Video streaming app (using a remote url) in swift. But there is no any exact video format. Sometimes it can be m3u8 sometimes mp4 etc.. but my video player should support for what ever the format comes from the back end.
Also when the app is in background, the audio should play and when the app comes foreground video should play without any time delay between the vide and the audio.
I want to know whether is it possible to achieve my objectives using AVPlayerViewController or else what is the best player that I can use to achieve my targets. Please help me.
Thanks
AVPlayerViewController supports m3u8 and mp4 both format. For playing video's audio you need some extra configuration. You can check from here...
How do I get my AVPlayer to play while app is in background?
Is it possible to play video using Avplayer in Background?
So according to me AVPlayerViewController is best option for your requirement.

Encrypted hls playback doesnot happen

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.

How to play .GIFV and .WEBM on iOS

I am making an reddit client app. So far I have been successfully able to play gif on iOS using FLAnimatedImage library. However for majority of the "gifs" now a days are "gifv" format from imgur and "webm" from gfycat.
Is there any way to play them on iOS? I researched and know that these 2 formats are just fancy videos. However even avplayer won't play them.
The official imgur app is able to play them so there has to be a way.
GIF formats are okay but problem arises for bigger files where we need to download the entire file first and that takes time. GIFV plays continuously without having to download the entire file. Hence I need someway to play them in my app.
#sschale thanks! yes, seems like imgur's gifv is basically mp4 video without audio. So I ended up using avplayer with each URL replaced with mp4 instead of gifv. Same webm replaced with mp4. Added a whole bunch of extra configuration for looping of video etc and got it to work seamlessly. In order for the avplayer to not pause background playing music of other apps, I added:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient withOptions:0 error:nil];

How to play YouTube video in iOS not in fullscreen?

I've been trying to get YouTube music videos to play in my iOS app in a small window (not full screen) and can't get it to work. I've tried the following:
I first used the YouTube API and created a YTPlayerView as instructed here: https://developers.google.com/youtube/v3/guides/ios_youtube_helper#adding_ytplayerview. This allowed me to play videos in-line, but many videos were unable to be played because of licensing issues, stating "This video contains content from *. It is restricted from playback on certain sites."
I then tried using a UIWebView, which successfully played the music videos that were previously unavailable. However, these videos were always forced to play in fullscreen mode, even when I set webView.allowsInlineMediaPlayback = YES;
I also tried embedding the video using the technique discussed here: How to embed YouTube video on iOs and play it directly on UIWebview without full screen. This worked to keep videos inline, but again, rendered certain videos unplayable.
I finally tried using an MPMoviePlayerController, but later found out that it can't actually play YouTube videos, as we don't have access to the direct links of video files, so this was another no-go.
Apps like PingTune were clearly able to figure this out using YouTube - they are able to play YouTube music videos in a custom, non-fullscreen view and without ads - what am I missing? Is there a part of the YouTube API that allows me to play these music videos that I implemented incorrectly?
I've never tried it myself but you could try LBYouTubeView by Laurin Brandner. LBYouTubeView is just a small view that is able to display YouTube videos in a MPMoviePlayerController. You even have the choice between high-quality and standard quality stream.
Code sample
LBYouTubePlayerViewController* controller = [[LBYouTubePlayerViewController alloc] initWithYouTubeURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=1fTIhC1WSew&list=FLEYfH4kbq85W_CiOTuSjf8w&feature=mh_lolz"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
controller.view.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
controller.view.center = self.view.center;
[self.view addSubview:self.controller.view];

iPad Movie Player Problem

I am playing mp4 files in iPad using MPMoviePlayerController. I have a view connected in IB to play the video files. The problem is that if one of the files is audio-only, it plays fine, but then videos that play after the audio file do not show the play/pause/seek controls.
I am doing this to initialize the view:
self.theMovie = [[MPMoviePlayerController alloc] init];
[self.viewForMovie addSubview:theMovie.view];
Has anyone seen this behavior or have an idea how I can get the video controls to reappear?
Thank you!
You can set the control type with
self.theMovie.controlStyle=MPMovieControlStyleDefault
These are the available options:
MPMovieControlStyleNone
MPMovieControlStyleEmbedded
MPMovieControlStyleFullscreen
MPMovieControlStyleDefault
Details here: http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

Resources