我的应用程序已超过95%,我有一个非常讨厌的错误,我真的需要一些帮助。 我有表格视图,其中包含流网址列表>我选择电影并加载>我有覆盖停止,暂停,音量和滚动视图与流,以在上一个流播放时切换流。 当我开始应用程序一切正常,所有流工作。 但是当我点击STOP按钮时,当前流停止并且mpmovieplayer关闭,我从一开始就再次进入表格视图。停止按钮代码就是这个(我是子类mpmovieplayer):
- (void) StopAndDismiss: (NSNotification *) notification
{
[mp stop]; // is MPMoviePlayerController object
[self dismissModalViewControllerAnimated:YES];
}
然后我从表中选择一些流,并且进程是相同的show mpmovieplayercontroller,加载影片的代码是:
-(void) ChannelFromMainChannelPicker: (NSNotification *)note
{
NSString *stringFromNote = (NSString *)[note object];
NSString *title = [[NSString alloc] initWithFormat:@"%@", stringFromNote];
cPlayer = [[CustomMoviePlayerController alloc] initWithUrlPath:title];
[self presentModalViewController:cPlayer animated:NO];
[cPlayer readyPlayer:stringFromNote];
[title release];
}
- (void)readyPlayer:(NSString *)p_url
{
if(mp != nil)
{
NSString *title = [[NSString alloc] initWithFormat:@"%@", p_url];
NSURL *n = [[NSURL alloc]initWithString:title];
[mp setContentURL:n];
mp.initialPlaybackTime = -1.0;
[title release];
[n release];
[mp play];
}
else
{
mp = [[MPMoviePlayerController alloc] initWithContentURL:movieUrlPath];
//[mp setAllowsWirelessPlayback:YES];
if ([mp respondsToSelector:@selector(loadState)])
{
// Set movie player layout
[mp setControlStyle:MPMovieControlStyleNone];
[mp setFullscreen:YES];
// May help to reduce latency
[mp prepareToPlay];
// Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerLoadStateChanged:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(SwitchToAnotherStreamUrl:)
name:@"notiSwitchToAnotherStreamUrl"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayerPlaybackStateDidChange:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(PauseStream:)
name:@"notiPauseStream"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(StopAndDismiss:)
name:@"notiStopAndDismiss"
object:nil];
}
}
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
但是当我现在从叠加流列表更改为其他流时,只有音频有效,但没有视频(只有黑屏)。但我再次加载相同的流,它正常加载它。但是当我按下STOP按钮后,每次第一次启动流时都会加载音频,我需要第二次调用它才能工作。 在我的自定义电影播放器中,我重载此方法,可能这里有一些问题:
- (void) moviePlayerPlaybackStateDidChange: (NSNotification *) notification
{
if(mp.playbackState == MPMoviePlaybackStateStopped)
{
NSLog(@"Loading so display activity indicator");
[[NSNotificationCenter defaultCenter] postNotificationName:@"notiShowLoader" object:nil];
}
else if (mp.playbackState == MPMoviePlaybackStatePlaying)
{
NSLog(@"Done with loading, hide activity indicator");
[[NSNotificationCenter defaultCenter] postNotificationName:@"notiHideLoader" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"notiBringCPToFront" object:nil];
}
else if (mp.playbackState == MPMoviePlaybackStatePaused)
{
NSLog(@"Movie is paused");
}
}
PS 有什么方法我可以检查音频加载和视频不是以某种方式迫使它重新加载播放器?
我添加了NSlog来检查播放状态。还有一些有线的东西,因为我称之为STOP下一个流,我尝试多次调用它:
0 MPMoviePlaybackStateStopped,
1 MPMoviePlaybackStatePlaying,
2 MPMoviePlaybackStatePaused,
3 MPMoviePlaybackStateInterrupted,
4 MPMoviePlaybackStateSeekingForward,
5 MPMoviePlaybackStateSeekingBackward
first time from table view
2011-01-21 13:46:04.865[3561:207] CURRENT PLAYBACK STATE ID = 1
second time from overlay
2011-01-21 13:46:30.338[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:46:30.461[3561:207] CURRENT PLAYBACK STATE ID = 1
STOP button press
2011-01-21 13:47:14.797[3561:207] CURRENT PLAYBACK STATE ID = 0
from table view
2011-01-21 13:47:31.123[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:31.123[3561:207] CURRENT PLAYBACK STATE ID = 1
from overlay again (ONLY AUDIO)
2011-01-21 13:47:50.001[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.001[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.119[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.119[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:47:50.148[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.148[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.149[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.149[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:47:50.150[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:47:50.150[3561:207] CURRENT PLAYBACK STATE ID = 0
third time (now works and audio and video)
2011-01-21 13:48:21.752[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.752[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.852[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:48:21.852[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.855[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.855[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.856[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.856[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.858[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:48:21.858[3561:207] CURRENT PLAYBACK STATE ID = 1
STOP second time
2011-01-21 13:49:39.046[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:49:39.046[3561:207] CURRENT PLAYBACK STATE ID = 0
again load from table
2011-01-21 13:50:00.155[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:00.155[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:00.155[3561:207] CURRENT PLAYBACK STATE ID = 1
from overlay
2011-01-21 13:50:27.211[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.211[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.211[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.325[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:50:27.326[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.326[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.333[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.333[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.333[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.334[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.335[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.335[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.336[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.336[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:50:27.337[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.339[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.339[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.339[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.340[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.340[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.340[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.341[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.341[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:50:27.342[3561:207] CURRENT PLAYBACK STATE ID = 1
again from overlay (only audio)
2011-01-21 13:56:56.198[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.198[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.198[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.335[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.335[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.335[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:56:56.338[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.338[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.338[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.339[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.339[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.340[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.341[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:56:56.341[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.341[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.359[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.359[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.359[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.360[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.360[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.360[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.361[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:56:56.361[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:56:56.361[3561:207] CURRENT PLAYBACK STATE ID = 0
same icon again (works)
2011-01-21 13:57:31.115[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:57:31.115[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.115[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.118[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.118[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.118[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.119[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.119[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.119[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.120[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.120[3561:207] CURRENT PLAYBACK STATE ID = 1
2011-01-21 13:57:31.121[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.131[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.131[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.131[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.132[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.132[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.132[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.133[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.134[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:57:31.134[3561:207] CURRENT PLAYBACK STATE ID = 1
STOP again
2011-01-21 13:58:17.318[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:17.318[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:17.318[3561:207] CURRENT PLAYBACK STATE ID = 0
play from table
2011-01-21 13:58:36.085[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:36.085[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:36.085[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:36.085[3561:207] CURRENT PLAYBACK STATE ID = 1
STOP
2011-01-21 13:58:53.599[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:53.599[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:53.599[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:53.600[3561:207] CURRENT PLAYBACK STATE ID = 0
PLAY from table again
2011-01-21 13:58:57.236[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:57.236[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:57.236[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:57.236[3561:207] CURRENT PLAYBACK STATE ID = 0
2011-01-21 13:58:57.236[3561:207] CURRENT PLAYBACK STATE ID = 1
答案 0 :(得分:1)
好的初学者错误,当我关闭自定义电影播放器时,我不知道我需要删除所有观察者。这解决了问题:
[mp stop];
[mp.view removeFromSuperview];
[self dismissModalViewControllerAnimated:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self];