ios - Mpmovieplayercontroller video pause while clicking button for another functional

标签 ios xcode macos mpmovieplayercontroller

我正在使用 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];
}

最佳答案

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

试试这个代码,它会工作

关于ios - Mpmovieplayercontroller video pause while clicking button for another functional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12088340/

相关文章:

java - 如何使 JDK 7 默认必须在 Mac OS X 10.9+ 上使用?

java - 如何在 Mac bash 上从命令行运行 Gradle

macos - 如何在 Mac OS X 上拍摄忽略应用程序窗口的区域的屏幕截图

android - 为什么 Google Flutter 中底部导航栏中的类似项目的文本大小不同?

从服务器加载数据的 iOS 事件

ios - 嵌入式二进制文件和链接框架之间有什么区别

iPhone/Objective - C - 如何在 UILabel 中显示长字符串的整个文本

ios - .pch 文件中的#define 不起作用

objective-c - 应用程序更新,将旧数据库数据转换为新数据库

ios - 如何在 iOS 11 的 UITextView 中禁用拖动