0

我正在开发的移动应用程序加载了一个 webview 视图控制器,它打开了在应用程序的 sqlite 数据库中定义的 URL,并将视频内容流式传输到应用程序内的播放器。

视频可以正常加载和播放,但每当我尝试关闭视图时它就会崩溃。

相关的obj-c代码是:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil gscreenvid:(NSString *)url {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        gscreenvid = url;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (gscreenvid != nil && [gscreenvid compare:@""] != 0) {
        NSURL *p_url = [NSURL URLWithString:gscreenvid];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:p_url];
        [webView loadRequest:requestObj];
    }
}

- (IBAction) cancelButtonTapped:(id) sender {
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
}
4

2 回答 2

0

为了解决我的问题,我将这些行添加到 viewDidLoad

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStateDidChange:) name:@"MPAVControllerItemPlaybackDidEndNotification" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerWillExitFullscreen) name:@"UIMoviePlayerControllerWillExitFullscreenNotification" object:nil];
}

- (void)playerWillExitFullscreen {
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"done");
}

- (void)playbackStateDidChange:(NSNotification *)note {
    NSLog(@"note.name=%@ state=%d", note.name, [[note.userInfo
    objectForKey:@"MPAVControllerNewStateParameter"] intValue]);
    [self.delegate dismissViewControllerAnimated:YES completion:nil];
}
于 2013-11-18T06:06:46.733 回答
0

我相信下面的行

[self.delegate dismissViewControllerAnimated:YES completion:nil];

应该

[self dismissViewControllerAnimated:YES completion:nil];

于 2013-09-30T10:49:38.613 回答