Adding videos to application - iphone

I want to store large number of videos in my application's directory. Will it make my application slow? Or will it take time to launch the application. I am loading videos only when necessary.

It will make large size of your application which is not good...& it will also take time to launch in place of save all ur video u can make user to download that video from server and after that it will be saved in ur doc directory so ur app will be not of large size.............

Where is it located locally
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"videoname" ofType:#"mov" inDirectory:#""]];
and play with that
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
[player release];
EDIT:-
The exact answer to this question is NO, it will not make your App Slow,But yeah it ill take some time to load the videos in your App,Time will depend upon number of videos you are loading in your APP. The solution to this is you have to use blocks for ALAssetLibaries.
Have a look on this ALAssetLibary Apple's class reference.
It may help you if not do contact me. Thanks :)

Related

How to play youtube videos inside iPhone app from the video url?

I am working on a project where I have to play some videos in my iPhone app. Is there any way so that I can play the videos directly using youtube video URL? I have to use lots of videos and I don't want to save them in my local iphone database. I am very new to this field.
In my project there will be a list of cancer disease. I mean blood cancer, bladder cancer, brain cancer etc. If a user clicks a particular cancer disease, then there should be a video regarding that cancer in the next view. I want to play that video directly (or something like that) using url. It should be like youtube video (streaming video). Is it possible?
This has been discussed many times on SO. Alternatively, theres an Open Source Project allowing this, that I recommend:
https://github.com/larcus94/LBYouTubeView
Add following frameworks: a) AVFoundation b) MediaPlayer
and write these import statements :
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>
and then write code whenever you want
NSURL *fileURL = [NSURL URLWithString:#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

Getting a black screen when trying to play a movie

When i'm trying to play a movie on my iPhone, it isn't work. I dont know why.. searched here and all over the internet, try 5 different codes, but still can't get it to work. I'm new to Obj-C, so please be patient.
I just want the movie to play and when the movie is done, to exit the player. also, at the beginning I dont want it to show a black screen, I want to see the first frame of the video instead. is it possible?
-(void)playTheMovie
{
NSURL *url = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:#"C061381" ofType:#"mp4" inDirectory:#""]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[player view] setFrame:[self.view bounds]]; // Frame must match parent view
[self.view addSubview:[player view]];
[player play];
}
Thanks!
Most probably you are messing up with the URL.
Check out Movie player sample project from apple
https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html
Run it first to confirm its functionality and then
Replace its movie with yours and change the extension and path name in the code
if it works copy the code to your project..

Open movie stream in another view

I have in my app a tab view with many tabs, and in one of them I have a button that when is clicked, I want to show a movie stream in a view. I have this code:
NSString *moviePath = #"http://10.0.0.4/prog_index.m3u8";
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:moviePath]];
[theMovie.view setFrame:CGRectMake(0, 0, (self.view.frame.size.width), (self.view.frame.size.height))];
theMovie.view.backgroundColor = [UIColor grayColor];
theMovie.view.tag = 9999;
[self.view addSubview:[theMovie view]];
[theMovie play];
The view appears, but the video doesn't start. What is wrong?
You're passing to the MPMoviePlayerController an URL pointing to a m3u8 file. That is a playlist. To play media with MPMoviePlayerController, you have to set it an actual video file. You should parse the playlist to get the link to the real video and then init your MPMoviePlayerController with the real link.
Check M3U - Wikipedia and MPMoviePlayerController reference
Also check this related question
EDIT: Thanks to Hugo Silva, I realized that MPMoviePlayerController is able to play live streams in m3u8 format, since I've not seen anything wrong in your code, I suggest you to check if it's a problem of your stream. Try using one of the samples provided by Apple. Also make sure that your stream meets Apple's requirements for HTTP Streaming

Playing Multiple Videos on iPAD

I am facing some problem in playing multiple videos on iPAD. I am trying to play multiple thumbnail videos on the same view. You can say its much like the CCTV camera.Well, i have no clue. Please help me. Thanks in advance...
MPMoviePlayerController will allow multiple instances, but only one of them can be playing their movie at any given time.
It mentions it here: http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
From the article:
Note: Although you may create multiple MPMoviePlayerController objects and present their views in your interface, only one movie player at a time may play its movie.
You can't use the MKMediaFramework to play multiple videos. You can however do this with the lower level AVFoundation Framework. It's not as hard as you might think and I've made a tutorial that goes over it here: http://www.sdkboy.com/?p=66
Essentially what you need to do is extend UIView so it contains an AVPlayerLayer to which the output of an AVPlayer object is directed, then you can create multiple instances of this UIView that you feed video using AVPlayer instances.
This is actually pretty simple to do on the iPad.
You basically need multiple MPMoviePlayerController objects.
Each MPMoviePlayerController object has a view property, you just need to set the frames of the views on the different MPMoviePlayerController objects to match what you want it to look like.
Here is a simple example using two MPMoviePlayerController objects ans 2 different frames:
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[[player view] setFrame: yourFrame1];
[myView addSubview: [player view]];
// ...
[player play];
MPMoviePlayerController *player2 =
[[MPMoviePlayerController alloc] initWithContentURL: myURL2];
[[player2 view] setFrame: yourFrame2];
[myView addSubview: [player2 view]];
// ...
[player2 play];
May be When Creating a WebView and using a HTML5 Video instance you can run multiple videos at the same time

MPMoviePlayerController questions, best practices

I have any number of thumbnail images that, when tapped, will play a different video (fullscreen). I have never been clear on whether I should keep one MPMoviePlayerController object in my view controller and have it play whichever url according to the thumbnail that was tapped, or create a new MPMoviePlayerController each time. What is the best practice?
I am also having problems where tapping on different thumbs crashes the app, I believe because the MPMoviePlayerController tries to stream a video while it is already trying to stream. There seems to be no way to cancel a MPMoviePlayerController and clear out what it was doing, then start loading a new video.
Here's how I create it:
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] init];
self.player = moviePlayer;
[moviePlayer release];
Then to play a video I do this:
//would like to do something like this first - [self.player clear];
self.player.contentURL = someURL;
[self.view addSubview:player.view];
[self.player prepareToPlay];
[self.player play];
Any advice is welcome... thanks.
When you are changing the video in an MPMovieplayerController,then you can remove the mpmoviecontrollerplayer view from super view using removeFromSuperView and again add it's subview to the super view initializing it with new URL.
No need to create new object every time.