如何在ios中停止播放EXC_BAD_ACCESS的视频

时间:2016-08-19 12:33:57

标签: ios objective-c avplayer avplayerlayer

这是我用于播放视频的代码, 我需要在点击按钮时停止视频,但它会抛出EXC_BAD_ACCESS异常,我在日志中收到以下消息

发送到已解除分配的实例的

消息

-(void) getallData{
    NSString * video=[dict valueForKey:@"abc"];
    NSString *strvideo = [NSString stringWithFormat:@"%@XXXX/XXX/%@",appDelegate.baseURL,video];
    NSURL *fileURL = [NSURL URLWithString: strvideo];
    avPlayer = [AVPlayer playerWithURL:fileURL];
    avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
    avPlayerLayer.frame = CGRectMake(2, 45, 724, 450);
    [self.view.layer addSublayer:avplayerLayer];
    [viewObj.layer addSublayer:avPlayerLayer];
    [avPlayer play];
}

-(IBAction)btnBackClick:(id)sender
{
    //I need to stop video here  
    [avPlayer pause];
}

0 个答案:

没有答案