2

initWithContentURL:MPMoviePlayerControllerで、最初にビデオファイルをダウンロードしてから再生を開始しますか、それともYouTubeのようにファイルをストリーミングしますか?

時間を無駄にしないために、サーバーにある動画をストリーミングで再生したい。

iPhoneでストリーミングを実行する方法は?あなたが知っているなら誰かが私に提案してもらえますか?

前もって感謝します。

4

1 に答える 1

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;
}

---------------------------上記の方法はiphoneのファイルシステムにビデオを保存するためのものです
------------ --------その映画の連続を再生するための以下の方法

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];
于 2011-01-17T10:57:41.137 に答える