我想在我的iOS应用程序中从URL流式传输在线广播,但只有当我将mp3文件的路径添加到我的项目并且不适用于在线mp3网址时,它才有效,这是我的代码,任何想法好吗?或者你有一个很好的教程如何流式传输在线文件,我看到很多教程,但他们都谈论本地mp3文件
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
{
AVAudioPlayer *_audioPlayer;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Construct URL to sound file
//NSString *path = [NSString stringWithFormat:@"%@/drum01.mp3", [[NSBundle mainBundle] resourcePath]]; // here when I uncomment the line it works fine
NSString *path = @"http://fileadress.mp3"; // here it doesn't work, it's an available link and I'm testing it on the simulator
NSURL *soundUrl = [NSURL fileURLWithPath:path];
// Create audio player object and initialize with URL to sound
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundUrl error:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)playSoundTapped:(id)sender
{
// When button is tapped, play sound
[_audioPlayer play];
}
@end
答案 0 :(得分:0)
&#34; AVAudioPlayer不支持通过HTTP进行流式传输。请尝试使用AVPlayer。&#34;