我正在尝试将视频添加到我的iOS应用程序,但只播放音频但没有视频

时间:2014-06-16 00:29:30

标签: ios objective-c video

我到处寻找答案并尝试了所有可能的方法,也许是我想念的一些简单的东西(我是编程的新手)我也有很多其他的东西在同一个故事板板文件中进行我有3个按钮来做其他我想要加载的应用程序,然后直接播放视频,然后转到同一个故事板上的主菜单。

继承我的代码:

viewcontroller.m文件:

    - (void)viewDidLoad
{
    [super viewDidLoad];


}

-(void)viewDidAppear:(BOOL)animated
{
    [self play];
}

- (void) play
{
    NSURL* url = [[NSBundle mainBundle] URLForResource:@"goatmovie1"        withExtension:@"mov"];

m_player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[m_player setControlStyle:MPMovieControlStyleNone];
[[m_player view] setFrame:[self.view frame]];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[m_player play];

[self.view addSubview:[m_player view]];
}

- (void) moviePlayBackDidFinish:(NSNotification*)_notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:nil];

[m_player.view removeFromSuperview];
[m_player stop];
m_player = nil;
}

这是我的.h文件:

#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface StartViewController : UIViewController
{
    MPMoviePlayerController* m_player;
}

- (void) play;

@end

1 个答案:

答案 0 :(得分:1)

安永

您可以尝试下一个链接:Video won't play on iPhone 5.0 simulator,还有几个链接,但这应该可行。

如果没有,请查看编码并查看Apple文档支持的格式:http://support.apple.com/kb/ht3775