当我在真实设备上测试我的无线电iOS应用程序时它有问题但是当屏幕或设备关闭时,收音机停止并关闭为什么会发生这种情况? 以及如何使活动指示器视图停止移动并在收音机打开并完成加载时将其隐藏???
(void)viewDidLoad
{
[super viewDidLoad];
timer=[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(uodatetimer) userInfo:nil repeats:YES];
player = [[MPMoviePlayerController alloc] initWithContentURL:
[NSURL URLWithString:@"http://46.43.64.50:8008/AJYAL.m3u"]];
player.movieSourceType = MPMovieSourceTypeStreaming;
player.view.hidden = YES;
[self.view addSubview:player.view];
[player prepareToPlay];
[player play];
// player.useApplicationAudioSession=NO;
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);
spinner.center=self.view.center;
[spinner startAnimating];
[self.view addSubview:spinner];
MPVolumeView *volumeView = [[[MPVolumeView alloc] initWithFrame:
CGRectMake(0, 0, 105, 15)] autorelease];
volumeView.center = CGPointMake(152,372);
[volumeView setShowsVolumeSlider:YES];
[volumeView setShowsRouteButton:YES];
[volumeView sizeToFit];
[self.view addSubview:volumeView];
}
答案 0 :(得分:1)
您需要做两件事才能在后台播放音频:
将音频会话类别设置为AVAudioSessionCategoryPlayback并激活音频会话:
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive:YES error:nil];
答案 1 :(得分:0)
为了能够在后台播放,您需要在项目.plist文件UIBackgroundModes
或人类可读格式的必需背景模式中启用,并在数组中启用第一个字符串行写入音频。这将使您的应用在屏幕关闭后和后台运行时运行。
答案 2 :(得分:0)
在yourProject-pList
添加此行