gpt4 book ai didi

iOS 流媒体背景音频

转载 作者:行者123 更新时间:2023-11-29 04:12:29 25 4
gpt4 key购买 nike

以下是仅用于获取音频流的代码:

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:stringURL]];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
connectionPlay = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSError *playerError;
player = [[AVAudioPlayer alloc] initWithData:streamData error:&playerError];
player.numberOfLoops = 0;
player.volume = 1.0f;
[player prepareToPlay];

if (playerError) {
NSLog(@"audio player error: %@", [playerError localizedDescription]);
}
if (player == nil)
NSLog(@"%@", [playerError description]);
else
[player play];

当我尝试将应用程序置于后台模式时,我会抓紧时间玩。我已进入 .plist 并输入“必需的背景模式,项目 0,应用程序播放音频”。这并没有解决我的问题。

我开始放置这个:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];
[[AVAudioSession sharedInstance] setActive:YES
error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

内部

- (void)applicationWillResignActive:(UIApplication *)application

- (void)applicationDidEnterBackground:(UIApplication *)application

主 ViewController 中的 viewDidLoad 内部。以及在[玩家prepareToPlay]之后。

我不确定问题是否出在我没有设置正确的后台设置或应用程序切断了连接。基本上,我不确定我错过了什么。

我一直在看:

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html

https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/Introduction/Introduction.html

编辑:有人吗?

最佳答案

我不知道它是什么,但我只是将所有代码转移到一个新项目,添加了此代码

 - (void)applicationWillResignActive:(UIApplication *)application
{

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:nil];
[[AVAudioSession sharedInstance] setActive:YES
error:nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

和plist设置,它似乎可以在手机上运行,​​但不能在模拟器上运行..

关于iOS 流媒体背景音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14206590/

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