我制作mpmovieplayerviewcontroller并在其中加载影片(来自流)。现在我调用setContentURL方法来更改URL并且它可以工作。当应用程序第一次启动时,按下按钮后会显示带按钮的视图,它会打开电影播放器并加载电影。但是当我调用代码时,setContentURL播放器首先关闭它,然后返回第一个视图,我必须再次单击播放按钮再次打开播放器(因此它会记住并加载新的URL)。切换URL时如何防止玩家自行关闭?这一定是个小问题,请帮忙:) 这是单击播放按钮时的代码(第一个视图)
-(void)initializeMovieFromStream:(NSString *)var
{
if(player != nil)
{
NSString *title = [[NSString alloc] initWithFormat:@"%@%@%@", @"http://"];
NSURL *nurl = [NSURL URLWithString:title];
NSLog(@"Switching channel...");
[player.moviePlayer setContentURL:nurl];
isMoviePaused = NO;
}
else
{
NSString *title = [[NSString alloc] initWithFormat:@"%@%@%@", @"http://"];
NSURL *nurl = [NSURL URLWithString:title];
player = [[MPMoviePlayerViewController alloc] initWithContentURL:nurl];
[player.moviePlayer.view.window setUserInteractionEnabled:YES];
player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
}
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(movieFinishedPlaying:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[player moviePlayer]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(nowPlayingMovieDidChange:)
name:MPMoviePlayerNowPlayingMovieDidChangeNotification
object:nil];
[self presentModalViewController:player animated:YES];
//[self presentMoviePlayerViewControllerAnimated:player];
UIView *mv = player.view;
//[mv setFrame:CGRectMake(0, 0, 320, 480)];
[mv addSubview:myOverlayChannelPicker];
[mv bringSubviewToFront:myOverlayChannelPicker];
// register this class to observe TestNotification that comes from OverlayChannelPicker
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(receiveTestNotification:)
name:@"TestNotification"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(pauseStreamNotificationHandler:)
name:@"notiPauseStream"
object:nil];
}
-(void) movieFinishedPlaying: (NSNotification *)note
{
[[NSNotificationCenter defaultCenter]
removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification
object:[player moviePlayer]];
//[player release];
}
当URL需要切换时,我使用这个硝化处理程序
- (void) receiveTestNotification:(NSNotification *) notification
{
NSString *stringFromNote = (NSString *)[notification object];
[switchableChannel setString:stringFromNote];
[self initializeMovieFromStream:stringFromNote];
}
解决了我只是将动画属性更改为NO。