直播支持flv格式,播放器停止功能待修复

This commit is contained in:
buvta
2021-01-15 22:07:33 +08:00
parent 4e5aab6f66
commit af768d527a
2 changed files with 23 additions and 8 deletions

View File

@@ -360,10 +360,11 @@ export default {
const parser = require('iptv-playlist-parser')
const playlist = fs.readFileSync(file, { encoding: 'utf-8' })
const result = parser.parse(playlist)
const supportFormats = /\.(m3u8|flv)$/
result.items.forEach(ele => {
const urls = ele.url.split('#').filter(e => e.startsWith('http')) // 网址带#时自动分割
urls.forEach(url => {
if (ele.name && url && (url.endsWith('.m3u8') || new URL.URL(url).pathname.endsWith('.m3u8'))) { // 网址可能带参数
if (ele.name && url && (supportFormats.test(url) || supportFormats.test(new URL.URL(url).pathname))) { // 网址可能带参数
const doc = {
id: id,
name: ele.name,

View File

@@ -261,7 +261,7 @@ import { exec, execFile } from 'child_process'
const { remote, clipboard } = require('electron')
const win = remote.getCurrentWindow()
const PinyinMatch = require('pinyin-match')
const URL = require('url')
const VIDEO_DETAIL_CACHE = {}
const addPlayerBtn = function (event, svg, attrs) {
@@ -372,7 +372,8 @@ export default {
currentShortcutList: [],
onlineUrl: '',
playerType: 'hls',
exportablePlaylist: false
exportablePlaylist: false,
changingIPTV: false
}
},
filters: {
@@ -459,6 +460,7 @@ export default {
},
video: {
handler () {
if (this.changingIPTV) return
this.getUrls()
},
deep: true
@@ -578,7 +580,6 @@ export default {
},
playChannel (channel) {
this.isLive = true
this.getPlayer('hls')
if (channel.channels) {
this.right.sources = channel.channels.filter(e => e.isActive)
channel = channel.prefer ? channel.channels.find(e => e.id === channel.prefer) : channel.channels.filter(e => e.isActive)[0]
@@ -589,25 +590,37 @@ export default {
channelList.add(ele)
this.right.sources = ele.channels.filter(e => e.isActive)
}
this.changingIPTV = true // 避免二次执行playChannel
this.video.iptv = channel
this.name = channel.name
const supportFormats = /\.(m3u8|flv)$/
const extRE = channel.url.match(supportFormats) || new URL.URL(channel.url).pathname.match(supportFormats)
this.getPlayer(extRE[1])
this.xg.config.isLive = true
this.xg.src = channel.url
this.xg.play()
document.querySelector('xg-btn-showhistory').style.display = 'none'
document.querySelector('.xgplayer-playbackrate').style.display = 'none'
this.changingIPTV = false
if (document.querySelector('xg-btn-showhistory')) document.querySelector('xg-btn-showhistory').style.display = 'none'
if (document.querySelector('.xgplayer-playbackrate')) document.querySelector('.xgplayer-playbackrate').style.display = 'none'
},
getPlayer (playerType, force = false) {
if (!force && this.playerType === playerType) return
this.xg.src = ''
if (this.playerType !== 'flv') {
this.xg.src = '' // https://developers.google.com/web/updates/2017/06/play-request-was-interrupted#danger-zone
}
this.config.url = ''
this.xg.destroy()
try {
this.xg.destroy()
} catch (err) { }
this.xg = null
switch (playerType) {
case 'mp4':
this.xg = new Player(this.config)
break
case 'flv':
this.config.videoStop = false
this.xg = new FlvJsPlayer(this.config)
this.config.videoStop = true
break
default:
this.xg = new HlsJsPlayer(this.config)
@@ -643,6 +656,7 @@ export default {
const ext = url.match(/\.\w+?$/)[0].slice(1)
this.getPlayer(ext)
}
this.xg.config.isLive = false
this.xg.src = url
const key = this.video.key + '@' + this.video.info.id
const startTime = VIDEO_DETAIL_CACHE[key].startPosition || 0