gpt4 book ai didi

iphone - 如何在 iPhone 中播放视频

转载 作者:行者123 更新时间:2023-12-03 21:21:00 26 4
gpt4 key购买 nike

MPMoviePlayerController 中的 initWithContentURL: 是首先下载视频文件然后开始播放还是会像 youtube 中那样流式传输文件?

我想通过流媒体播放位于服务器中的视频,以免浪费时间。

如何在 iPhone 中进行串流?如果你知道的话,有人可以建议我吗?

提前致谢。

最佳答案

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

关于iphone - 如何在 iPhone 中播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4711557/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com