iOS 音乐流和 HTTP Live Streaming

3

我有几个关于音频流的问题:

我的目标是流式传输一些mp3文件,大多数都是3到7分钟的音乐文件,但这些mp3文件由不是我的服务器提供。需要说明的是,我想让我的应用被Appstore接受。

1°/我需要通过http流式传输一些128Kbps的mp3音乐文件。我真的需要使用HTTP Live Streaming服务(HLS)吗?

2°/如果我必须使用HLS,我需要重新编码我的mp3文件为64Kbps,还是只需分段它们?

谢谢!


我还没有做过音频流媒体... 我认为你不需要使用HLS进行音频流媒体... 请查看我在此链接中关于视频流媒体的帖子 http://stackoverflow.com/questions/10597884/iphone-ipad-downloading-and-playing-simultaneously/10601021#10601021 - Dilip Rajkumar
你尝试过直接将mp3的URL提供给播放器来播放音频吗? - Dilip Rajkumar
1个回答

0

我正在使用这段代码播放音频。据我所知,您不需要使用HLS,您可以直接流式传输,或者您必须移动音频的元数据。我已经在另一个答案中给出了步骤iPhone/iPad同时下载和播放。请检查。

// add the necessary frameworks    
#import <CoreAudio/CoreAudioTypes.h>
#import <AVFoundation/AVFoundation.h>
// put the code in .h file
AVAudioPlayer * avPlayer;

-(IBAction) stopPlayingAudio {
    [avPlayer stop];
}

- (IBAction)showVoiceRecordingMenu
{

    // Create an otherwise-empty alert sheet
    avPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://test.com/audio/files/audioFile.mp3"] error:&error];

    NSLog(@"%@", [filePath path] ); 
    NSLog(@"%f", avPlayer.duration );
    itsAudioDuration = avPlayer.duration;
    [avPlayer prepareToPlay];
    [avPlayer play];
}

谢谢回答!但是我知道如何从mp3流式传输音乐。我只是想知道如果我不使用HLS来流式传输我的mp3,我的应用程序是否会被App Store拒绝... - user1432439
我尝试了这段代码(以及其他类似的代码),但没有任何声音播放。我也没有看到服务器上的任何请求。我已经检查过我的URL是正确的。当我让AVAudioPlayer播放时,它没有任何反应。 - Matt
抱歉回复晚了,马特。我不在站内,请问你能给我文件的URL吗? - Dilip Rajkumar
1
AVAudioPlayer不支持HTTP资源。https://developer.apple.com/library/ios/#qa/qa2009/qa1634.html - kain
@kain 抱歉我之前回答得很久远了,我已经记不起来任何东西了。如果您知道正确答案,请回答这个问题。这将有助于未来的某些人。 - Dilip Rajkumar
将AVAudioPlayer更改为AVPlayer对我很有用,代码基本相同,但可以轻松从http资源流式传输!https://dev59.com/LGcs5IYBdhLWcg3wGgNc?lq=1 - Jack Dewhurst

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接