MPMoviePlayerController 在视图卸载后继续播放?

发布于 2024-12-04 05:44:54 字数 967 浏览 7 评论 0原文

我有一个详细视图,当详细视图控制器中的 viewdidload 时,MPMoviePlayerController 分配并播放音频,但即使我导航回主表,音频仍在播放。

当我导航回主表时如何停止 MPMovieplayercontroller ?这是我的 MPMoviePlayerController 代码:

.h

MPMoviePlayerController *player;

.m

- (void)viewDidLoad
{
[super viewDidLoad];
//Get the Movie
NSURL *movieURL = [NSURL URLWithString:@"some link"];
player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

//Place it in subview, else it won’t work
player.view.frame = CGRectMake(20, 20, 280, 25);
player.backgroundView.backgroundColor = [UIColor clearColor];
[self.view addSubview:player.view];

// Play the movie.
[player play];

}

我什至将以下代码添加到 viewdidunload 方法中,但不起作用。

- (void)viewDidUnload {

[player stop];
player.initialPlaybackTime = -1;
[player release];

// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

你们有什么建议?

提前致谢,

I have a detail view, and when viewdidload in detailviewcontroller, MPMoviePlayerController allocs and plays an audio, but even if I navigate backto main table, audio is still being played.

How can I stop MPMovieplayercontroller when I navigate back to main table ? This is my MPMoviePlayerController code:

.h

MPMoviePlayerController *player;

.m

- (void)viewDidLoad
{
[super viewDidLoad];
//Get the Movie
NSURL *movieURL = [NSURL URLWithString:@"some link"];
player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

//Place it in subview, else it won’t work
player.view.frame = CGRectMake(20, 20, 280, 25);
player.backgroundView.backgroundColor = [UIColor clearColor];
[self.view addSubview:player.view];

// Play the movie.
[player play];

}

I even added following code into viewdidunload method, but didn't work.

- (void)viewDidUnload {

[player stop];
player.initialPlaybackTime = -1;
[player release];

// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

What do you guys suggest ?

Thanks in advance,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼中杀气 2024-12-11 05:44:54

与 viewWillDisappear 相比,我更喜欢 viewDidDisappear 的用户体验。动画开始,电影停止 - 这样音频对我来说流动得更好。

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_moviePlayer stop];
}

I liked the user experience of viewDidDisappear better than viewWillDisappear. The animation starts and the movie stops after - the audio flows better for me this way.

-(void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [_moviePlayer stop];
}
夜无邪 2024-12-11 05:44:54

我有类似的问题。我无法使用“viewDidDisappear”或“viewWillDisappear”,因为我有一个“config”类型视图,可以在播放内容时打开它,并且它将触发这两种方法。

编辑:发现 viewDidUnload 和 viewWillUnload 不再被调用(我当前使用的是 iOS 6+ 设备)...

来自文档:

可用性:iOS(3.0 及更高版本)已弃用:视图不再可用
在低内存条件下被清除,因此永远不会调用此方法。

我刚刚创建了一个名为 unload 的简单函数,并在函数内部将我需要的任何对象设置为 = nil (我正在使用 ARC)。当我调用删除视图时,我也调用了卸载函数。希望它能帮助某人。

I am having a similar issue. I am unable to use "viewDidDisappear" or "viewWillDisappear" because I have a "config" type view that can be opened while the content is playing, and it will trigger those two methods.

EDIT: Found that viewDidUnload and viewWillUnload are not getting called any more (I'm currently on an iOS 6+ device)...

From the documentation:

Availability: iOS (3.0 and later) Deprecated: Views are no longer
purged under low-memory conditions and so this method is never called.

I just created a simple function called unload, and inside the function, set any objects I needed to = nil (I'm using ARC). At the time that I make the call to remove the view, I call the unload function as well. Hope it helps someone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文