我在ViewController中只使用了1 MPMoviePlayerController
。我正在做的是一个ViewController,其中我有一个滚动视图,其中有4-5个子视图,用户可以执行不同的操作,如在MPMoviePlayerController
中观看视频,键入一些文本,使用步进控制来评价等
当用户去VC观看视频&回到家用VC&再次尝试回去:
Getting Error Assertion failure: movie player has wrong activation state (1)
这是Only happens in adhoc build
。当我尝试在调试模式下重新调试时,我只是没有看到这个错误。这有点令人困惑。
请查看以下代码并提出更改建议。
我在方法中这样初始化。
void SomeMethod(){
this.MoviePlayer = new MPMoviePlayerController ();
this.MoviePlayer.View.Frame = new RectangleF (AppConstants.ZeroVal,contentHeight, VIEW_WIDTH, 200);
this.MoviePlayer.ControlStyle = MPMovieControlStyle.Default;
this.MoviePlayer.SourceType = MPMovieSourceType.Streaming;
this.MoviePlayer.ScalingMode = MPMovieScalingMode.Fill;
this.MoviePlayer.ContentUrl = NSUrl.FromString(_someUrl_);
}
并在Button的TouchUpInside
中 btnObj.TouchUpInside+=((ss,ee)=>{
this.MoviePlayer.View.Hidden = false;
containerView.Add (this.MoviePlayer.View);
BtnPlayFeedbackUserRespVideo.Hidden = true;
this.MoviePlayer.Play ();
});
ViewDidLoad中的
public override void ViewDidLoad(){
// Keyboard popup
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.DidShowNotification,KeyBoardUpNotification);
// Keyboard Down
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.WillHideNotification,KeyBoardDownNotification);
MPMoviePlayerController.Notifications.ObservePlaybackDidFinish(HandleMoviePlayerStoppedPlaying);
MPMoviePlayerController.Notifications.ObserveWillExitFullscreen (HandleDidExitFullScreen);
MPMoviePlayerController.Notifications.ObserveWillEnterFullscreen(HandleDidEnterFullScreen);
}
private void HandleDidExitFullScreen(object ss,NSNotificationEventArgs ee){
IsPlayingFullScreen = false;
if (this.MoviePlayer != null) {
this.MoviePlayer.Pause ();
}
}
private void HandleDidEnterFullScreen(object ss,NSNotificationEventArgs ee){
IsPlayingFullScreen = true;
if (this.MoviePlayer != null) {
this.MoviePlayer.Pause ();
}
}
private void HandleMoviePlayerStoppedPlaying(object ss,MPMoviePlayerFinishedEventArgs ee){ //MPMoviePlayerFinishedEventArgs ee){
if (this.MoviePlayer != null) {
if (ee.FinishReason == MPMovieFinishReason.PlaybackEnded || ee.FinishReason == MPMovieFinishReason.UserExited || ee.FinishReason == MPMovieFinishReason.PlaybackError) {
InvokeOnMainThread (() => {
if (ReviewState) {
if (SelectedLastChallengeForeview != null) {
this.MoviePlayer.ContentUrl = NSUrl.FromString (SelectedChallengeForReview.ResponseVideoUrl);
} else {
if (SelectedChallengeForReview != null) {
this.MoviePlayer.ContentUrl = NSUrl.FromString (SelectedChallengeForReview.ResponseVideoUrl);
}
}
} else {
this.MoviePlayer.ContentUrl = NSUrl.FromString(FeedbackToSubmit.ResponseVideoUrl);
}
this.MoviePlayer.View.Hidden = true;
BtnPlayFeedbackUserRespVideo.Hidden = false;
this.MoviePlayer.PrepareToPlay();
});
}
}
}
在ViewWillDisappear视图中
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
if (IsPlayingFullScreen) {
return;
}
if (!IsSubmittingFeedback && !ReviewState) {
if (this.MoviePlayer != null) {
this.MoviePlayer.Stop ();
}
NSNotificationCenter.DefaultCenter.RemoveObserver (MPMoviePlayerController.WillEnterFullscreenNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver (MPMoviePlayerController.WillExitFullscreenNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver (MPMoviePlayerController.PlaybackDidFinishNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver (UIKeyboard.DidShowNotification);
NSNotificationCenter.DefaultCenter.RemoveObserver (UIKeyboard.DidHideNotification);
PopToActivityVC (false);
}
}
答案 0 :(得分:0)
我知道这有点老了但不久就遇到了类似的问题。
请记住,使用Ad-Hoc创建二进制文件时,应用优化设置通常设置为高(默认情况下)。这可能会影响您的应用的时间安排。打开调试方案的优化设置,您应该能够复制问题。
您的代码看起来不错。对Swift来说不是很好,但翻译它并没有出现任何问题。
您还应该保持警惕,在正确的时间添加和删除通知。这也可以触发您所看到的问题。