Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AvAudioSession赢得';你不能在iOS7中工作吗? #导入“SctreamAudioViewController.h” #进口 #导入“SecondViewController.h” @接口SctreamAudioViewController() @属性(非原子,强)AVPlayer*player; @结束 @sctreamudioviewcontroller的实现 #定义流@”http://localhost/audio.mp3" -(无效)viewDidLoad { [超级视图下载]; //加载视图后,通常从nib执行任何其他设置。 AVAudioSession*audioSession=[AVAudioSession sharedInstance]; [音频会话设置类别:AvaudioSessionCategory播放和记录选项:AVAudioSessionCategoryOptionDefaultToSpeaker错误:无]; [audioSession setActive:是错误:无]; NSURL*url=[[NSURL alloc]initWithString:STREAM]; self.player=[[AVPlayer alloc]initWithURL:url]; } -(iAction)播放:(id)发送方{ [self.player play]; }_Ios_Avplayer_Avaudiosession - Fatal编程技术网

AvAudioSession赢得';你不能在iOS7中工作吗? #导入“SctreamAudioViewController.h” #进口 #导入“SecondViewController.h” @接口SctreamAudioViewController() @属性(非原子,强)AVPlayer*player; @结束 @sctreamudioviewcontroller的实现 #定义流@”http://localhost/audio.mp3" -(无效)viewDidLoad { [超级视图下载]; //加载视图后,通常从nib执行任何其他设置。 AVAudioSession*audioSession=[AVAudioSession sharedInstance]; [音频会话设置类别:AvaudioSessionCategory播放和记录选项:AVAudioSessionCategoryOptionDefaultToSpeaker错误:无]; [audioSession setActive:是错误:无]; NSURL*url=[[NSURL alloc]initWithString:STREAM]; self.player=[[AVPlayer alloc]initWithURL:url]; } -(iAction)播放:(id)发送方{ [self.player play]; }

AvAudioSession赢得';你不能在iOS7中工作吗? #导入“SctreamAudioViewController.h” #进口 #导入“SecondViewController.h” @接口SctreamAudioViewController() @属性(非原子,强)AVPlayer*player; @结束 @sctreamudioviewcontroller的实现 #定义流@”http://localhost/audio.mp3" -(无效)viewDidLoad { [超级视图下载]; //加载视图后,通常从nib执行任何其他设置。 AVAudioSession*audioSession=[AVAudioSession sharedInstance]; [音频会话设置类别:AvaudioSessionCategory播放和记录选项:AVAudioSessionCategoryOptionDefaultToSpeaker错误:无]; [audioSession setActive:是错误:无]; NSURL*url=[[NSURL alloc]initWithString:STREAM]; self.player=[[AVPlayer alloc]initWithURL:url]; } -(iAction)播放:(id)发送方{ [self.player play]; },ios,avplayer,avaudiosession,Ios,Avplayer,Avaudiosession,我在网上做了很多研究,我认为这应该是在后台播放音频的正确方式。然而,它就是不起作用。我不知道哪里出了问题。请帮忙。谢谢。查找UIBackgroundModes。你需要告诉系统你的应用程序将在后台播放声音 #import "SctreamAudioViewController.h" #import <AVFoundation/AVFoundation.h> #import "SecondViewController.h" @interface SctreamAudioViewCont

我在网上做了很多研究,我认为这应该是在后台播放音频的正确方式。然而,它就是不起作用。我不知道哪里出了问题。请帮忙。谢谢。

查找UIBackgroundModes。你需要告诉系统你的应用程序将在后台播放声音

#import "SctreamAudioViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "SecondViewController.h"

@interface SctreamAudioViewController ()
@property (nonatomic, strong) AVPlayer *player;
@end

@implementation SctreamAudioViewController

#define STREAM @"http://localhost/audio.mp3"

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
[audioSession setActive:YES error:nil];
NSURL *url = [[NSURL alloc] initWithString:STREAM];
self.player = [[AVPlayer alloc] initWithURL:url];
}

- (IBAction)play:(id)sender {

[self.player play];
}
如果你想在应用程序处于后台时播放音频,你应该使用类别播放而不是playAndRecord。 此外,您需要在project->target->Capabilities->backgroundMode中检查音频和播放

[[AVAudioSession sharedInstance] setActive:NO error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
我认为http在您的定义中是不正确的。试着把它当作

#define STREAM @"http://"
凭什么?您的意思是在此列表中的“所需背景模式”下添加“应用程序播放音频”?您确定可以访问吗?您正在运行http服务器吗?您是否正确配置并启动了它?
#define STREAM (@"file://")