1

我想知道你們中的任何人是否遇到過類似的問題,當然碰巧找到了正確的或不正確的(但工作中)的解決方案/解決方法。MPMoviePlayerViewController上的UIGestureRecognizer

我正在使用MPMoviePlayerViewController,我試圖將一個Swipe-Gesture識別器添加到MPMoviePlayerViewControllers視圖中。

moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:currentChannel.StreamURI]];
[moviePlayerViewController.movi​​ePlayer setControlStyle:MPMovieControlStyleNone];
moviePlayerViewController.movi​​ePlayer.movi​​eSourceType = MPMovieSourceTypeStreaming;
moviePlayerViewController.movi​​ePlayer.shouldAutoplay = YES;
[moviePlayerViewController.movi​​ePlayer setScalingMode:MPMovieScalingModeAspectFit];我們可以使用UISwipeGestureRecognizer * swipeGestureRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(previousChannel)];
swipeGestureRight.direction = UISwipeGestureRecognizerDirectionRight;
[myMoviePlayerViewController.view addGestureRecognizer:swipeGestureRight];
[self.view addSubview:moviePlayerViewController.view];

無論如何,它「有點作品」,但是當我通過在正在運行的電影播放器​​實例(無論是在模擬器還是在設備上)上執行手勢來測試整個事件時,應用程序崩潰,控制檯狀態

** -[CFRunLoopTimer invalidate]: message sent to deallocated instance 0xf074bb0 

沒有任何人對此主題有想法嗎?

回答

1

看來,iOS正在釋放您的MPMoviePlayerViewController對象,然後再發送消息給它。我會建議把你的實例類的成員,然後實例的屬性吧,比如:

@property (nonatomic, retain) MPMoviePlayerViewController *moviePlayerViewController; 

...與相應的@synthesize聲明你的類的實現文件一起。當分配你的對象,你應該然後做:

self.moviePlayerController = [[[MPMoviePlayerViewController alloc] initWithContentURL:@"yourUrl"] autorelease]; 

最後,通過在dealloc方法將其設置爲nil釋放對象。