English 中文(简体)
如何在MPMoviePlayerController中停止视频下载
原标题:How to stop Video download in MPMoviePlayerController

我有一个要求,需要播放一个位于远程位置的视频文件。

我将URL传递给MPMoviePlayerController实例并调用了play方法。

现在,电影正在下载。在电影完全加载之前,我点击了“完成”按钮并返回了根视图。

MPMoviePlayerPlaybackDidFinishNotification通知被调用。我已经停止了视频并释放了播放器。这是代码。

- (void)movieDidFinish:(NSNotification *)aNotifciation
{

    [self.moviePlayer stop];

    [self removeActivityIndicatorView];

    [self.tableView reloadData];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:nil];

    [moviePlayer release];

    moviePlayer = nil;

}

但是,视频仍在后台加载,我也能听到音频。

这件事一定不能发生。

有人能提供这个问题的解决方案吗?

问题回答
[movieplayer stop];
movieplayer.initialPlaybackTime = -1.0;
[movieplayer release]; 

将初始播放时间设置为-1可能会解决您的问题。

您负责登记MoviePlayerController议员在宣誓就职时发出的国家公报。 例如:

[[NSNotificationCenter defaultCenter]  
    addObserver:self 
       selector:@selector(movieFinishedCallback:)                                                  
           name:MPMoviePlayerPlaybackDidFinishNotification 
         object:player]; 

把它放在你的主视图控制器类的“viewDidLoad”里是一个好的位置。

然后,在您的方法“movieFinishedCallback:”中(其中作为参数传递了NSNotification对象,您可以使用它来了解发生的完成类型的更多细节,如果您喜欢的话),您只需关闭movieplayercontroller即可。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签