【发布时间】:2013-12-04 03:44:38
【问题描述】:
#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];
}
我在网上做了很多研究,我认为这应该是在后台播放音频的正确方法。但是,它只是行不通。我不知道哪里出了问题。请帮忙。谢谢。
【问题讨论】:
-
您确定localhost 可以访问吗?你在运行http服务器吗?您是否正确配置并启动它?
标签: ios avplayer avaudiosession