【问题标题】:Getting video to play in simulator让视频在模拟器中播放
【发布时间】:2010-10-07 19:52:10
【问题描述】:

所以我的应用程序中会弹出一个警报视图,单击视图按钮时应该播放视频,但模拟器中没有任何反应。我不想在设备上测试它,直到我让它在模拟器中工作。据我所知,这是下面的代码应该可以工作。它到达 Log 语句并输出到控制台,但视频不播放。有什么想法吗?

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex{
    if (buttonIndex == 1) {
        NSURL *url = [NSURL URLWithString:@"http://srowley.co.uk/endyVid.mp4"];
        MPMoviePlayerController *player = [[[MPMoviePlayerController alloc] initWithContentURL:url] autorelease];

        //---play movie---
        [player setFullscreen:YES];
        [self.view addSubview:[player view]];
        NSLog(@"Player Should play!");
        [player play]; 
    }
}

【问题讨论】:

    标签: iphone xcode video ios-simulator


    【解决方案1】:

    你需要在玩家的视野中设置框架。

        [[player view] setFrame: [self.view bounds]];
    

    【讨论】:

    • 把它放进去不会改变任何东西:(
    • 您不能将播放器创建为自动释放的对象,否则它会在有机会播放之前解除分配。将其分配给一个属性或 ivar,并在用户看完电影后释放它。
    • 另外,您可能想要使用 didDismissWithButtonIndex: 而不是 clickedButtonAtIndex:。前者在运行之前等待警报视图消失,这似乎是您在播放视频之前想要的。
    猜你喜欢
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    相关资源
    最近更新 更多