0

MPMovieplayerController用于播放视频,而我点击其他按钮,即我想暂停我的视频,无论它再次播放。我点击播放意味着我想在暂停时播放。但对我来说,现在点击按钮意味着我的视频已停止。但我想暂停而不是停止。我的示例代码在这里

    - (IBAction) playvideo
{
    NSURL *url = [NSURL URLWithString:@"http://xyz/video1.mp4"];
    movieplayer = [[[MPMoviePlayerController alloc]initWithContentURL:url] retain]; 
movieplayer.view.frame=CGRectMake(25,54,658,460);    
    [self.view addSubview:movieplayer.view];
    [movieplayer play];
}

-(void)buttononclick
{

    [movieplayer pause];
    [movieplayer.view removeFromSuperview];

    for (int i = 0; i < 13; i++)
    {
CGRect frame;
frame.origin.x = 150 * i;
frame.origin.y = 0;
frame.size = CGSizeMake(140, self.scrollView.frame.size.height);
        [scrollView setShowsHorizontalScrollIndicator:NO];



        UIImageView *temp1 = [[UIImageView alloc] initWithFrame:CGRectMake(25, 7, 75, 75)];
        [temp1 setImage:[UIImage imageNamed:@"sti15.png"]];
        [self.scrollView addSubview:temp1];


        UIImageView *temp2 = [[UIImageView alloc] initWithFrame:CGRectMake(110, 7, 75, 75)];
        [temp2 setImage:[UIImage imageNamed:@"sti16.png"]];
        [self.scrollView addSubview:temp2];


        UIImageView *temp3 = [[UIImageView alloc] initWithFrame:CGRectMake(195, 7, 75, 75)];
        [temp3 setImage:[UIImage imageNamed:@"sti17.png"]];
        [self.scrollView addSubview:temp3];

}
    self.scrollView.contentSize = CGSizeMake(165 * 10, self.scrollView.frame.size.height);
    self.scrollView.pagingEnabled=0;
}

- (void)viewDidDisappear:(BOOL)animated
{
   // [self setDescText:nil];
[super viewDidDisappear:animated];
    [movieplayer pause];
    [movieplayer.view removeFromSuperview];
}
4

3 回答 3

3
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ((movie.playbackState==MPMoviePlaybackStateStopped)||(movie.playbackState==MPMoviePlaybackStatePaused)) 
    {
        [movie play];  
    }
    else
    {
        [movie pause];
    }
}

试试这个代码,它会工作

于 2014-09-06T12:17:06.383 回答
0

查看MPMoviePlaybackStatePlayingMPMoviePlaybackStateStoppedMPMoviePlaybackStatePaused和的通知MPMoviePlaybackStateInterrupted

就像是:

MPMoviePlayerController *player = notification.object;
/* Playback is currently stopped. */
    if (player.playbackState == MPMoviePlaybackStateStopped)
    {
        NSLog(@"MPMoviePlaybackStateStopped");
    }

/*  Playback is currently under way. */
    else if (player.playbackState == MPMoviePlaybackStatePlaying)
    {        
        NSLog(@"MPMoviePlaybackStatePlaying");
        }

/* Playback is currently paused. */
    else if (player.playbackState == MPMoviePlaybackStatePaused)
    {
        NSLog(@"MPMoviePlaybackStatePaused");
    }

您可以像这样连接您的目标操作:

if ((_moviePlayer.playbackState == MPMoviePlaybackStateStopped) || (_moviePlayer.playbackState == MPMoviePlaybackStatePaused)) {
            [_moviePlayer play];
        } else {
            [_moviePlayer pause];
        }
于 2012-11-25T16:07:01.183 回答
0

您可以将目标添加到播放/暂停按钮。但首先你需要抓住 mpmovieplayerview 的按钮。

第 1 步列出按钮。方法参考从这里

从按钮出现时调用此方法(视频准备就绪)。但请记住,这也会捕获全屏按钮和播放按钮。(如果可用)

- (void)CatchSubviewsOfView:(UIView *)view {

// Get the subviews of the view
NSArray *subviews = [view subviews];

for (UIView *subview in subviews) {

    // Do what you want to do with the subview
    NSLog(@"%@", subview);
    if(subview isKindOfClass:[UIButton class]]){
        // add your target here
        [subview addTarget:self action:@selector(extraAction:) forControlEvents:UIControlEventTouchUpInside];
    }

    // List the subviews of subview
    [self listSubviewsOfView:subview];
}
}

步骤 2 执行操作

-(IBAction)extraAction:(id)sender{
    NSLog(@"some extraAction");
}

调用 catch 方法示例。[self CatchSubviewOfView:movieplayer.view];

于 2015-06-15T12:32:25.497 回答