gpt4 book ai didi

iphone - 无法使用 MPMoviePlayerViewController 播放视频

转载 作者:可可西里 更新时间:2023-11-01 03:06:27 24 4
gpt4 key购买 nike

我使用以下 ViewController.m 创建了一个新项目。当我运行该应用程序时,我可以看到一个具有预期原点/大小(38、100、250、163)的框,但它是黑色的并且没有播放视频。 Xcode 中有一个奇怪的输出:

2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay
2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)

注意视频是用Videora iPhone Converter转换的,在Xcode中播放正常(所以不是视频问题);视频的路径没问题,因为当我指定 demo-iPhone1(它不存在)时,我得到一个 nil 异常。我在模拟器和 iPhone 上试过:总是黑盒子。有任何想法吗?

#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController ()

@end

@implementation ViewController
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];

[moviePlayerController.view removeFromSuperview];
}


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(38,
100,
250,
163)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

最佳答案

我刚刚用这行代码解决了一个类似的问题。播放器 Controller 现在出现并且视频播放完美:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer;
//
@synthesize moviePlayer = _moviePlayer;
//
[self.moviePlayer prepareToPlay];

修改以适应您的环境。

关于iphone - 无法使用 MPMoviePlayerViewController 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12099393/

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