【发布时间】:2015-08-03 07:27:02
【问题描述】:
我想在我的 iOS 应用程序中从 URL 流式传输在线广播,但它仅在我将 mp3 文件的路径添加到我的项目中并且不适用于在线 mp3 url 时才有效,这是我的代码,任何请问有什么想法吗?或者你有关于如何流式传输在线文件的好教程,我看过很多教程,但它们都在谈论本地 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
【问题讨论】:
标签: ios iphone server mp3 radio