Tôi gặp rất nhiều sự cố khi hiển thị phim toàn màn hình trong ứng dụng iPad của mình và sau đó cho phép người dùng loại bỏ nó bằng nút Xong hoặc "un-fullscreen" trên các nút điều khiển trình phát.Hiển thị và loại bỏ toàn màn hình MPMoviePlayerController trong iOS 3.2 (iPad)
Ban đầu tôi đang sử dụng MPMoviePlayerViewController
cho bản trình chiếu phim, nhưng tôi đã không nhận được thông báo toàn màn hình nhập/thoát từ đối tượng MPMoviePlayerController
của mình, vì vậy tôi đã chuyển sang tự làm.
Tôi có thể làm phim xuất hiện toàn màn hình (mặc dù quá trình chuyển đổi) nhưng khi nhấn nút "Xong" hoặc "không có toàn màn hình", người chơi sẽ không thực hiện thao tác nào. Tôi đã đăng mã của tôi dưới đây:
- (void)startPlayingMovieWithURLString:(NSString *)movieURLString {
// I get all of these callbacks **EXCEPT** the "willExitFullScreen:" callback.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.moviePlayerController setContentURL:someExistingURL];
// "self" is a UIViewController subclass, and is presented as a "fullscreen" modal view controller from its parent
// I'm setting the movie player's view's frame to take up the full rectangle of my view controller, but really I want the movie to be completely removed when the user presses "done" (that is, removed from the view hierarchy). Not sure when/where to do this.
self.moviePlayerController.view.frame = self.view.frame;
[self.view addSubview:self.moviePlayerController.view];
[self.moviePlayerController setFullscreen:YES animated:YES];
}
Và đây là mã cho callback didFinish tôi
- (void)didFinishPlayback:(NSNotification *)notification {
// This ends up recursively telling the player that playback ended, thus calling this method, thus…well you get the picture.
// What I'm trying to do here is just make the player go away and show my old UI again.
[self.moviePlayerController setFullscreen:NO animated:YES];
}
Vì vậy, rõ ràng là tôi đang làm một cái gì đó sai nhưng tôi đã được lên và xuống các tài liệu hướng dẫn và tôi không thể tìm ra cách làm cho bộ phim biến mất. Tôi nghĩ nó sẽ trực quan hơn thế này. Tôi đang làm gì sai?
Điều này hữu ích và tôi có thể thoát chế độ toàn màn hình ngay khi người dùng nhấn xong, tuy nhiên -playbackFinished: gọi lại không bao giờ được thực hiện cho tôi và tôi không thể cho cuộc sống của tôi tìm ra lý do tại sao không. Bạn có biết bất kỳ lý do nào tại sao điều này có thể xảy ra không? – jbrennan
Ngay cả khi phim phát đến hết? Lạ thật, tôi chưa bao giờ gặp phải điều đó. –
nếu MPMoviePlayerDidExitFullscreenNotification được gọi là cả khi chạm vào "Xong" và khi thoát toàn màn hình, làm sao bạn biết cái nào được gọi? Có lẽ người dùng chỉ thoát toàn màn hình trong trường hợp bạn không muốn xóa chế độ xem mà tôi đoán. –