Skip to content

Commit

Permalink
fiddling till it's fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelKreil committed Jul 28, 2017
1 parent cebe143 commit 5bf4c67
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
48 changes: 24 additions & 24 deletions bin/lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ function Player() {
var playProcess = false;
var nextTask = false;

function stop(cb) {
console.log('stop');
if (!playProcess) return cb();
function stopVideo() {
if (!playProcess) return;

nextTask = false;
playProcess.removeAllListeners('exit');
playProcess.stdout.removeAllListeners('data');
playProcess.kill();
playProcess = false;
}

function play(filename) {
console.log('play once "'+filename+'"');
if (playProcess) throw Error();
function playVideo(filename) {
if (playProcess) stopVideo();

playProcess = child_process.spawn('ffmpeg', [
'-loglevel','error',
Expand All @@ -32,8 +32,8 @@ function Player() {
'-f','rawvideo',
'-vcodec','rawvideo',
'-pix_fmt','rgb24',
'-']
)
'-'
])

playProcess.stdout.on('data', sendFrame);
playProcess.stderr.on('data', chunk => console.error(chunk.toString()));
Expand All @@ -43,25 +43,25 @@ function Player() {
});
}

function playOnce(filename) {
if (playProcess) stop();
nextTask = false;
play(filename);
}

function playLoop(filename, cb) {
if (playProcess) stop();
nextTask = () => play(filename);
nextTask();
}

function sendFrame(chunk) {
socket.send(chunk, config.matePort, config.mateHost);
}

return {
stop:stop,
playOnce:playOnce,
playLoop:playLoop
stop:() => {
console.log('stop');
nextTask = false;
stopVideo();
},
playOnce:(filename) => {
console.log('play once "'+filename+'"');
nextTask = false;
playVideo(filename);
},
playLoop:(filename) => {
console.log('play loop "'+filename+'"');
nextTask = () => playVideo(filename);
nextTask();
}
}
}
4 changes: 1 addition & 3 deletions bin/lib/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ function Video(filename, player) {
})

me.play = cb =>
player.stop(() =>
player.playLoop(filename, () => cb())
)
player.playLoop(filename)

me.generateThumbnail = cb =>
getFrameCount(filename, n =>
Expand Down

0 comments on commit 5bf4c67

Please sign in to comment.