我尝试在单独的UIView中播放视频,这样我就可以留出一些空间供控制工具使用,比如开始/停止等按钮,所以我写了以下代码:
首先,我创建了一个名为Single View Application的iOS项目,然后我在storyboard中添加了一个View,最后,我基于VideoView追加了一个新的UIView类,然后将该View与VideoView类关联,并编写了以下代码:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize moviePlayer;
- (IBAction)playMovie:(id)sender
{
VideoView *videoView = [[VideoView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:@"Sanda" ofType:@"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
//[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 476)];
[moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:moviePlayer.view];
[moviePlayer prepareToPlay];
[moviePlayer play];
}
好的,我来翻译一下。这段内容与IT技术有关,提到了在iOS上无法看到视频,只能听到声音,作者对iOS还不是很熟悉,希望得到一些提示。