forked from c10342/player
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
c10342
committed
Nov 10, 2020
1 parent
66e62c6
commit 19e003d
Showing
5 changed files
with
124 additions
and
104 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,53 @@ | ||
(function () { | ||
const express = require('express') | ||
|
||
const fs = require('fs') | ||
|
||
const app = express() | ||
|
||
app.get('/video', function (req, res) { | ||
let pathSrc = req.query.video | ||
let stat = fs.statSync(pathSrc); | ||
let fileSize = stat.size; | ||
let range = req.headers.range; | ||
// fileSize 3332038 | ||
if (range) { | ||
//有range头才使用206状态码 | ||
let parts = range.replace(/bytes=/, "").split("-"); | ||
let start = parseInt(parts[0], 10); | ||
let end = parts[1] ? parseInt(parts[1], 10) : start + 999999; | ||
|
||
// end 在最后取值为 fileSize - 1 | ||
end = end > fileSize - 1 ? fileSize - 1 : end; | ||
|
||
let chunksize = (end - start) + 1; | ||
let file = fs.createReadStream(pathSrc, { | ||
start, | ||
end | ||
}); | ||
let head = { | ||
'Content-Range': `bytes ${start}-${end}/${fileSize}`, | ||
'Accept-Ranges': 'bytes', | ||
'Content-Length': chunksize, | ||
'Content-Type': 'video/mp4', | ||
}; | ||
res.writeHead(206, head); | ||
file.pipe(res); | ||
} else { | ||
let head = { | ||
'Content-Length': fileSize, | ||
'Content-Type': 'video/mp4', | ||
}; | ||
res.writeHead(200, head); | ||
fs.createReadStream(pathSrc).pipe(res); | ||
} | ||
}) | ||
|
||
app.listen(6789, () => { | ||
console.log('localhost:6789') | ||
}) | ||
|
||
})() | ||
const { log } = require("console"); | ||
|
||
(function() { | ||
const express = require("express"); | ||
|
||
const fs = require("fs"); | ||
|
||
const app = express(); | ||
|
||
app.get("/video", function(req, res) { | ||
let pathSrc = req.query.video; | ||
|
||
let stat = fs.statSync(pathSrc); | ||
let fileSize = stat.size; | ||
let range = req.headers.range; | ||
// fileSize 3332038 | ||
|
||
if (range) { | ||
//有range头才使用206状态码 | ||
let parts = range.replace(/bytes=/, "").split("-"); | ||
let start = parseInt(parts[0], 10); | ||
let end = parts[1] ? parseInt(parts[1], 10) : start + 999999; | ||
|
||
// end 在最后取值为 fileSize - 1 | ||
end = end > fileSize - 1 ? fileSize - 1 : end; | ||
|
||
let chunksize = end - start + 1; | ||
let file = fs.createReadStream(pathSrc, { | ||
start, | ||
end, | ||
}); | ||
let head = { | ||
"Content-Range": `bytes ${start}-${end}/${fileSize}`, | ||
"Accept-Ranges": "bytes", | ||
"Content-Length": chunksize, | ||
"Content-Type": "video/mp4", | ||
}; | ||
res.writeHead(206, head); | ||
file.pipe(res); | ||
} else { | ||
let head = { | ||
"Content-Length": fileSize, | ||
"Content-Type": "video/mp4", | ||
}; | ||
res.writeHead(200, head); | ||
fs.createReadStream(pathSrc).pipe(res); | ||
} | ||
}); | ||
|
||
app.listen(6789, () => { | ||
console.log("localhost:6789"); | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,74 @@ | ||
import Vue from 'vue' | ||
import axios from 'axios' | ||
import store from './store' | ||
import Vue from "vue"; | ||
import axios from "axios"; | ||
import store from "./store"; | ||
// import flvjs from "flv.js"; | ||
|
||
import i18n from './lang' | ||
// window.flvjs = flvjs; | ||
|
||
import './font-awesome-4.7.0/css/font-awesome.css' | ||
import './base.css' | ||
import i18n from "./lang"; | ||
|
||
import { MessageBox, Col, Row } from 'element-ui' | ||
import "./font-awesome-4.7.0/css/font-awesome.css"; | ||
import "./base.css"; | ||
|
||
Vue.prototype.$prompt = MessageBox.prompt; | ||
import { MessageBox, Col, Row } from "element-ui"; | ||
|
||
Vue.use(Col) | ||
Vue.use(Row) | ||
Vue.prototype.$prompt = MessageBox.prompt; | ||
|
||
Vue.use(Col); | ||
Vue.use(Row); | ||
|
||
import App from './App' | ||
import MyHeader from './components/Header' | ||
import MyVideo from './components/Video' | ||
import MyFooter from './components/Footer' | ||
import PlayList from './components/PlayList' | ||
import MyProgress from './components/Progress' | ||
import VideoProgress from './components/VideoProgress' | ||
import ListItem from './components/ListItem' | ||
import HistoryItem from './components/HistoryItem' | ||
import About from './components/About' | ||
import FileInfo from './components/FileInfo' | ||
import App from "./App"; | ||
import MyHeader from "./components/Header"; | ||
import MyVideo from "./components/Video"; | ||
import MyFooter from "./components/Footer"; | ||
import PlayList from "./components/PlayList"; | ||
import MyProgress from "./components/Progress"; | ||
import VideoProgress from "./components/VideoProgress"; | ||
import ListItem from "./components/ListItem"; | ||
import HistoryItem from "./components/HistoryItem"; | ||
import About from "./components/About"; | ||
import FileInfo from "./components/FileInfo"; | ||
|
||
Vue.component('MyHeader', MyHeader) | ||
Vue.component('MyVideo', MyVideo) | ||
Vue.component('MyFooter', MyFooter) | ||
Vue.component('PlayList', PlayList) | ||
Vue.component('MyProgress', MyProgress) | ||
Vue.component('VideoProgress', VideoProgress) | ||
Vue.component('ListItem', ListItem) | ||
Vue.component('HistoryItem', HistoryItem) | ||
Vue.component('About', About) | ||
Vue.component('FileInfo', FileInfo) | ||
Vue.component("MyHeader", MyHeader); | ||
Vue.component("MyVideo", MyVideo); | ||
Vue.component("MyFooter", MyFooter); | ||
Vue.component("PlayList", PlayList); | ||
Vue.component("MyProgress", MyProgress); | ||
Vue.component("VideoProgress", VideoProgress); | ||
Vue.component("ListItem", ListItem); | ||
Vue.component("HistoryItem", HistoryItem); | ||
Vue.component("About", About); | ||
Vue.component("FileInfo", FileInfo); | ||
|
||
if (!process.env.IS_WEB) Vue.use(require('vue-electron')) | ||
Vue.http = Vue.prototype.$http = axios | ||
Vue.config.productionTip = false | ||
if (!process.env.IS_WEB) Vue.use(require("vue-electron")); | ||
Vue.http = Vue.prototype.$http = axios; | ||
Vue.config.productionTip = false; | ||
|
||
import { ipcRenderer } from 'electron' | ||
import storage from 'good-storage' | ||
import { ipcRenderer } from "electron"; | ||
import storage from "good-storage"; | ||
|
||
// 窗口关闭前,保存store中的状态,以便下次打开恢复上次的状态 | ||
ipcRenderer.on('close', () => { | ||
storage.set('locale',i18n.locale) | ||
if (store.state.currentVideo && !store.state.isTrace) { | ||
storage.set('state', Object.assign({}, store.state, { currentVideo: { ...store.state.currentVideo, currentTime: store.state.currentTime, speed: store.state.speed } })) | ||
} else { | ||
storage.set('state', store.state) | ||
} | ||
}) | ||
|
||
|
||
ipcRenderer.on("close", () => { | ||
storage.set("locale", i18n.locale); | ||
if (store.state.currentVideo && !store.state.isTrace) { | ||
storage.set( | ||
"state", | ||
Object.assign({}, store.state, { | ||
currentVideo: { | ||
...store.state.currentVideo, | ||
currentTime: store.state.currentTime, | ||
speed: store.state.speed, | ||
}, | ||
}) | ||
); | ||
} else { | ||
storage.set("state", store.state); | ||
} | ||
}); | ||
|
||
new Vue({ | ||
components: { App }, | ||
template: '<App/>', | ||
store, | ||
i18n | ||
}).$mount('#app') | ||
|
||
components: { App }, | ||
template: "<App/>", | ||
store, | ||
i18n, | ||
}).$mount("#app"); |