【问题标题】:Can't stream radio from online url iOS无法从在线 url iOS 流式传输广播
【发布时间】: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


    【解决方案1】:

    “AVAudioPlayer 不支持通过 HTTP 进行流式传输。请尝试使用 AVPlayer。”

    https://stackoverflow.com/a/6095568

    【讨论】:

      猜你喜欢
      • 2012-03-23
      • 2011-06-17
      • 1970-01-01
      • 2012-12-22
      • 2012-05-13
      • 2014-09-02
      • 2016-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多