【问题标题】:Audio only HLS with iOS带有 iOS 的纯音频 HLS
【发布时间】:2012-06-28 13:28:08
【问题描述】:

我正在尝试在我的应用程序中添加一个可以在后台播放的纯音频播放器。 最初我使用了 MPMoviePlayerController,它工作得很好,但问题是它不支持向前和向后搜索(或使用滑块)。

有些录制长达一个小时,如果有人在录制过程中被打断并想回到他们原来的位置,他们必须从头开始。在我看来,使用 AVAudioCoder 是解决方案,所以我更改了我的代码,发现它不适用于不在设备上的 URL。

我确实使用 Http Live Streaming,并且有一个 .m3u8 文件。是否有一种易于实施的解决方案来使用来自 Internet 源的 .m3u8 和 .mp3 文件,并且能够使用滑块更改播放位置。 (由于需要在后台播放,所以不能使用 MPMoviePlayerController 的接口)

更新: 回来使用 MPMoviePlayerController,但有些奇怪的行为。播放.m3u8播放列表,设置新位置时,查询currentPlaybackTime时给出的值设置为正确的值,但声音继续播放,好像没有中断一样。

暂停播放器时,设置时间它只是忽略它并继续播放,但至少“currentPlaybackTime”给出正确的当前位置。

id appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate]; 双倍长度 = [[appDelegate audioPlayer] 持续时间]; 如果(长度 > 0){ 浮动滑块值 = [_滑块值]; 双倍时间 = sliderValue / 100 * 长度;

NSTimeInterval playBackTime = time;

NSLog(@"Requested time: %f vs current time %f", playBackTime, [[appDelegate audioPlayer] currentPlaybackTime]);
//[[appDelegate audioPlayer] pause];
[[appDelegate audioPlayer] setCurrentPlaybackTime:playBackTime];
//[[appDelegate audioPlayer] setInitialPlaybackTime:playBackTime];
//[[appDelegate audioPlayer] play];
NSLog(@"Requested time: %f vs current time %f (2)", playBackTime, [[appDelegate audioPlayer] currentPlaybackTime]);

}

我每秒钟更新一次标签,这给了我如上所述的行为:

id appDelegate = (iDomsAppDelegate *)[[UIApplication sharedApplication] delegate];

双倍时间 = [[appDelegate audioPlayer] currentPlaybackTime]; 双倍长度 = [[appDelegate audioPlayer] 持续时间]; NSLog(@"状态:%i,时间:%f",[[appDelegate audioPlayer]playbackState],[[appDelegate audioPlayer] currentPlaybackTime]); 如果(长度 > 0){ 双位置 = 时间/长度 * 100; [_slider setValue:(float)pos]; [_slider setEnabled:true];

NSInteger seconds = (int) length % 60;
NSInteger minutes = ((int) length / 60) % 60;

double playableDuration = [[appDelegate audioPlayer] playableDuration];
if(playableDuration > 0 && playableDuration < length){
    int downloaded = (int)((float)((float)playableDuration / (float)length) * 100);
    [_unknownLength setText:[NSString stringWithFormat:@"Total duration: %02i:%02i (%02i%% downloaded)", minutes, seconds, downloaded]];   
} else {
    [_unknownLength setText:[NSString stringWithFormat:@"Total duration: %02i:%02i", minutes, seconds]];       
}

} 其他 { [_slider setEnabled:false]; [_unknownLength setText:[NSString stringWithFormat:@"总持续时间未知"]];
}

NSInteger seconds = (int) time % 60; NSInteger 分钟 = ((int) 时间 / 60) % 60; [_position setText: [NSString stringWithFormat:@"%02i:%02i", 分, 秒]];

【问题讨论】:

  • 为什么你认为 MPMoviePlayerController 不支持与 HTTP 流相关的搜索?
  • 好问题。我认为将播放头移动到某个位置是一种私有方法,但重新阅读 MPMediaPlayback 协议的规范似乎表明不同。不知道为什么它不起作用,但我会再看看。
  • 放心,它就像一个魅力。 :D
  • 我正在努力让它工作。代码似乎没问题,我使用滑块找到一个新位置,但声音只是继续,没有跟随变化。我会更新问题
  • 我想知道,它只是音频的一个因素吗?

标签: iphone ios mpmovieplayercontroller http-live-streaming


【解决方案1】:

仅适用于 FFMPEG 的音频分段无法正常工作,但现在已在 GIT 存储库的头部修复。使用 MPMoviePlayer 控制器现在效果很好,可以快速找到分段大小的步骤。

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 2018-12-18
    • 2021-04-08
    • 2016-03-31
    • 2021-10-28
    • 2017-01-30
    • 2021-07-01
    • 1970-01-01
    • 2015-05-10
    相关资源
    最近更新 更多