gpt4 book ai didi

iphone - 当应用程序进入后台时 MPMoviePlayer 继续播放

转载 作者:行者123 更新时间:2023-12-03 20:43:16 28 4
gpt4 key购买 nike

我正在使用 iOS5

我正在开发 HTTPLivestream 项目。这里我使用 MPMovieplayer ,我的问题是当应用程序转到后台时没有音频。我正在后台模式下更改 plist 为音频。但是没有结果请帮助我。

应用删除

- (void)applicationDidEnterBackground:(UIApplication *)application {
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];

UIApplication *app = [UIApplication sharedApplication];
backgroundTask = [app beginBackgroundTaskWithExpirationHandler:^{
}];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
});
}

RadioControlView

  NSString *path =[[NSString alloc] initWithString:@"http://*******/alayam/alayam/playlist.m3u8"];

audioUrl=[NSURL URLWithString:path];

appDelegate.player = [[MPMoviePlayerController alloc] initWithContentURL:audioUrl];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(loadStateDidChange:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:appDelegate.player];
if ([appDelegate.player respondsToSelector:@selector(loadState)])
{
[appDelegate.player setControlStyle:MPMovieControlModeVolumeOnly];
[appDelegate.player setFullscreen:YES];
[appDelegate.player prepareToPlay];
}

- (void)loadStateDidChange:(NSNotification *)notification
{
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:appDelegate.player];

}

提前致谢

最佳答案

需要结合ios5中的后台支持设置进行远程控制设置-

//注册您的应用程序以进行远程控制

if([[UIApplication sharedApplication]  respondsToSelector:@selector(beginReceivingRemoteControlEvents)])
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];


// allows you to play in the background when app is suspended in iOS5
[[AVAudioSession sharedInstance] setDelegate: self];
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];

将这两个设置放在应用程序 didFinishLaunching 委托(delegate)中

关于iphone - 当应用程序进入后台时 MPMoviePlayer 继续播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9477338/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com