2

does initWithContentURL: in MPMoviePlayerController download the video file at first and then start playing or will it stream file like in youtube?

I want to play an video located in server through streaming in order not to waste of time.

How to perform streaming in iphone? Can anyone please suggest me if u know.

Thanks in advance.

JOM
  • 8,139
  • 6
  • 78
  • 111
SriPriya
  • 1,240
  • 15
  • 22

1 Answers1

1
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

if (!documentsDirectory) {
    NSLog(@"Documents directory not found!");
}
NSString *appFile;
NSArray *myWords = [[NSString stringWithFormat:@"%@",[[videolistArray objectAtIndex:[number intValue]] valueForKey:@"video"]] componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];
appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];
NSFileManager *fileMgr=[NSFileManager defaultManager];
if (![fileMgr fileExistsAtPath:appFile]) {
    NSData *imageData;
    NSURL *imageURL = [[[NSURL alloc] initWithString:[[videolistArray objectAtIndex:[number intValue]] valueForKey:@"video"] ] autorelease];
    if (imageURL) {
        imageData = [NSData dataWithContentsOfURL:imageURL];
    }

    [imageData writeToFile:appFile atomically:YES];
}
[pool release];


if (spinner) {
    [spinner stopAnimating];
    [spinner removeFromSuperview];
    [spinner release];
    spinner = nil;
}

---------------------------Above methode is for save video in file system of iphone
-------------------- Below method to play that movie continuos

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

if (!documentsDirectory) {

    NSLog(@"Documents directory not found!");

}

NSArray *myWords = [videoString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]];


NSString *appFile = [documentsDirectory stringByAppendingPathComponent:[myWords lastObject]];

NSLog(@"%@",[myWords lastObject]);

NSURL *url = [NSURL fileURLWithPath:appFile];

self.videoMPPlayer =[[MPMoviePlayerController alloc] initWithContentURL:url];

    self.videoMPPlayer.view.frame = CGRectMake(0, 0, 320, 480);

    self.videoMPPlayer.scalingMode = MPMovieScalingModeAspectFill;

    self.videoMPPlayer.controlStyle = MPMovieControlStyleNone;


    // Register for the playback finished notification

    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(movieLoadStateChanges:) name:MPMoviePlayerLoadStateDidChangeNotification object:videoMPPlayer];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:videoMPPlayer];


// Movie playback is asynchronous, so this method returns immediately.
[self.videoMPPlayer play];
JOM
  • 8,139
  • 6
  • 78
  • 111
GhostRider
  • 1,197
  • 10
  • 19
  • Hi., thank you, for the answer, do we have to download the complete file before start playing?is it not possible to download as streaming? is there any option other than MPMoviePlayer for streaming video file? – SriPriya Jan 19 '11 at 07:19
  • for this just use the following code from NSURL *url = [NSURL fileURLWithPath:@"Link of vidoe"]; – GhostRider Jan 19 '11 at 08:45
  • converting url string to NSURl and if i used in initWithContentURL: , the movie player starts play after getting data from the webservice, till that time player doesnot play anything, I need get video file data from webservice and also play the retrieved data simultaneously, as like youtube retrieves data and plays simultaneously. – SriPriya Jan 19 '11 at 09:58
  • have you give interview in the morning ? – GhostRider Jan 19 '11 at 10:18
  • no. i didnt,where it happened? do u get any idea of retrieving data and playing like in youtube? – SriPriya Jan 19 '11 at 13:01
  • just pass your url to webview its will play video like youtube – GhostRider Jan 20 '11 at 10:16
  • thank you, i will use it.., till now i am thinking MPMoviePlayer wont do streaming, i get it, that it supports streaming, thanks a lot for your valuable suggestions. – SriPriya Jan 27 '11 at 12:03
  • Hi, please help me with this question http://stackoverflow.com/questions/9432043/how-to-relay-h-264-stream :) – why Feb 24 '12 at 14:25