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

、、、、およびの通知を確認してMPMoviePlaybackStatePlayingください。MPMoviePlaybackStateStoppedMPMoviePlaybackStatePausedMPMoviePlaybackStateInterrupted

何かのようなもの:

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 に答える