gpt4 book ai didi

ios - 如何在 iOS 中从本地或服务器 URL 播放视频

转载 作者:IT王子 更新时间:2023-10-29 08:17:40 25 4
gpt4 key购买 nike

如何在 iOS 中从 Internet URL 或本地文件播放 .mp4 或 .mov 视频?

最佳答案

1.首先在XCode中添加MediaPlayer.Framework

2.然后在你的viewController的.h文件中添加#import < MediaPlayer/MediaPlayer.h >

3.现在在你的 viewDidLoad 方法中实现这段代码

     //NSString *filepath = [[NSBundle mainBundle] pathForResource:@"aaa" ofType:@"mp4"];  
//NSURL *fileURL = [NSURL fileURLWithPath:filepath];

NSURL *fileURL = [NSURL URLWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

对于方向,请添加此代码

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[moviePlayerController.view setFrame:CGRectMake(0, 0, 480, 320)];
}
return YES;
}

在这段代码中moviePlayerController是在.h文件中声明的MPMoviePlayerController

关于ios - 如何在 iOS 中从本地或服务器 URL 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6026942/

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