2012-03-17 57 views
0

我一直在試圖弄清楚如何讓我的電影視圖上的「播放符號」,以便用戶只需按下該按鈕,視頻就會開始播放。任何人都知道如何實現?電影播放器​​iOS5在視圖上播放符號

-(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; 
} 

回答

0

您可以創建一個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]; 

一旦你添加完movieplayer到視圖....您需要攜帶PLAYBUTTON的面前就像....

[self.view bringSubviewToFront:playButton]; 

記住這一點,一旦你已經添加了movieplayer到視圖做...

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