Android HLS-流式传输无法获取细分 [英] Android HLS- Streaming failed to fetch segment
问题描述
我为Android编写了一个Videoplayer,用于通过HLS流式传输视频.在我的服务器上,我有m3u8-Playlist和.ts-Segments. 我的代码如下:
I write a Videoplayer for Android to stream Video over HLS. On my Server I have the m3u8-Playlist and the .ts-Segments. My Code look like this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vidSurface = (SurfaceView) findViewById(R.id.surfView);
vidHolder = vidSurface.getHolder();
vidHolder.addCallback(this);
}
public void surfaceCreated(SurfaceHolder arg0) {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setDisplay(vidHolder);
mediaPlayer.setDataSource(vidAddress);
mediaPlayer.prepareAsync();
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
}
catch(Exception e){
e.printStackTrace();
}
}
对于Apple bipbopall.m3u8示例,播放器工作正常.但是当我尝试播放我的播放列表时,会发生此错误:
The Player works fine for the Apple bipbopall.m3u8 example. But when I try to play my Playlist this error occurs:
E/PlaylistFetcher﹕ failed to fetch .ts segment at url 'http://example.com/USSM.mp4Frag1Num0.ts'
E/LiveSession﹕ XXX Received error -1008 from PlaylistFetcher.
E/MediaPlayer﹕ error (1, -1008)
我认为文件的AES-128解密存在问题. MediaPlayer是否可以自己解密文件,如何检查解密是否成功? (我使用最新的Android版本)
I think there is a problem with the AES-128 decryption of the files. Does the MediaPlayer decrypt the files by him self and how can I check if the decryption was successful? (I use the latest Android-Version)
推荐答案
在评论中继续讨论:
1008
为ERROR_OUT_OF_RANGE
.通过下载片段,解密片段并尝试播放片段来检查服务器是否正确响应(请参见下面的方法).
1008
is ERROR_OUT_OF_RANGE
returned when trying to read the segment into a buffer. Check if the server is properly responding by downloading a segment, decrypting it and attempting to play it back (see method below).
要检查的其他事项:确保MPEG-TS
段有效.如果您使用MP4
文件中包含的H.264
流创建段,请检查它们是否使用Annex B
格式(例如,在ffmpeg
中,您可以使用h264_mp4toannexb
位流过滤器)编码流-您可以将其与-c:v copy
)
Other things to check: make sure the MPEG-TS
segments are valid. If you used the H.264
stream contained in an MP4
file to create the segments check if they're using the Annex B
format (for eg. in ffmpeg
you can use the h264_mp4toannexb
bitstream filter which works on the encoded stream - you can use it with -c:v copy
)
要检查加密是否正确,请使用openssl
.
To check if the encryption is correct use openssl
.
-
以普通十六进制格式获取密钥
Get the key in plain hex
xxd -p keyfile.key
解密.ts
段
openssl aes-128-cbc -d -in encrypted_segment.ts -out decrypted_segment.ts -nosalt -iv <iv_hex> -K <key_hex>
如果没有定义的IV,则它等于媒体序列.
If there's no defined IV then it is equal to the media sequence.
尝试播放解密的片段.
这篇关于Android HLS-流式传输无法获取细分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!