我有一个.m3u8文件。我想使用JavaScript解析它以获取带宽。播放列表如下所示
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000, RESOLUTION=720x480
http://ALPHA.mycompany.com/lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=200000, RESOLUTION=720x480
http://BETA.mycompany.com/lo/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=500000, RESOLUTION=1920x1080
http://ALPHA.mycompany.com/md/prog_index.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=500000, RESOLUTION=1920x1080
http://BETA.mycompany.com/md/prog_index.m3u8
最佳答案
试试这个代码:
var lines = file.split(/[\r\n]/);
for (var i in lines){
var line = lines[i];
if (/BANDWIDTH/.test(line)) {
var keyVal = line.split(/ /)[1],
val = keyVal.split(/[=,]/)[1];
console.log(val);
}
}
希望能帮助到你。
关于javascript - 如何使用JavaScript解析m3u8播放列表以获取带宽?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38712340/