【问题标题】:Movie player iOS5 play symbol over view电影播放器​​ iOS 5 播放符号概述
【发布时间】:2012-03-17 18:36:14
【问题描述】:

我一直在试图弄清楚如何在我的电影视图顶部获得“播放符号”,以便用户只需按下它,视频就会开始播放。有人知道如何实现吗?

-(void)viewDidLoad
{
//Video player
NSString *url = [[NSBundle mainBundle] pathForResource:self.navigationItem.title ofType:@"mov"];

_player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath: url]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerPlaybackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:_player];
_player.view.frame = CGRectMake( 350, 200, 400, 400);
[self.view addSubview:_player.view];
}

//Plays the movie once the "Play" button is pressed 
-(IBAction)playMovie
{
[_player play];
}

//Exits fullscreen when movie is finished
- (void) playerPlaybackDidFinish:(NSNotification*)notification
{
_player.fullscreen = NO;
}

【问题讨论】:

    标签: objective-c ios5 xcode4.2 mpmovieplayercontroller


    【解决方案1】:

    您可以为您的按钮创建一个 IBOutlet,或者您必须自己通过这样的代码添加播放按钮...(以便通过代码访问它。)

      // Add play button 
      playButton = [[UIButton alloc] initWithFrame:CGRectMake(53, 212, 214, 36)];    
      [playButton setBackgroundImage:[UIImage imageNamed:@"playButton.png"] forState:UIControlStateNormal];
      [playButton addTarget:self action:@selector(buttonPressed:) forControlEvents: UIControlEventTouchUpInside];    
      [[self view] addSubview:playButton];  
    

    一旦你完成了将电影播放器​​添加到视图中......你需要将播放按钮放在前面,就像......一样。

    [self.view bringSubviewToFront:playButton];
    

    记住,一旦你将电影播放器​​添加到视图中,就必须这样做......

    来源...http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-05
      相关资源
      最近更新 更多