Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A way to get back to normal video speed #120

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ app.on('ready', function () {
})

ipc.on('open-file-dialog', function () {
var files = dialog.showOpenDialog({ properties: [ 'openFile', 'multiSelections' ]})
var files = dialog.showOpenDialog({ properties: [ 'openFile', 'multiSelections' ] })
if (files) {
files.forEach(app.addRecentDocument)
win.send('add-to-playlist', files)
Expand Down Expand Up @@ -110,11 +110,8 @@ app.on('ready', function () {
globalShortcut.register('MediaPreviousTrack', function () {
win.send('media-previous-track')
})

})

app.on('will-quit', function () {

globalShortcut.unregisterAll()

})
61 changes: 36 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@ $('#controls-timeline').on('click', function (e) {
media.time(time)
})

function updateTimelineTooltip(e) {
function updateTimelineTooltip (e) {
var tooltip = $('#controls-timeline-tooltip')[0]
var percentage = e.pageX / $('#controls-timeline')[0].offsetWidth
var time = formatTime(percentage * media.duration)
var time = formatTime(percentage * media.duration)
tooltip.innerHTML = time
tooltip.style.left = (e.pageX - tooltip.offsetWidth / 2) + "px"
tooltip.style.left = (e.pageX - tooltip.offsetWidth / 2) + 'px'
Copy link

@dawsbot dawsbot Feb 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few linting changes in this diff that seem unnecessary, can these be removed, so it's only a functionality PR?

}

$('#controls-timeline').on('mousemove', function (e) {
Expand All @@ -222,27 +222,34 @@ $('#controls-timeline').on('mouseout', function (e) {
var isVolumeSliderClicked = false
var isPbrateSliderClicked = false

function updateAudioVolume(value) {
function updateAudioVolume (value) {
media.volume(value)
}

function updateVolumeSlider(volume) {
function updateVolumeSlider (volume) {
var val = volume.value * 100
volume.style.background = '-webkit-gradient(linear, left top, right top, color-stop(' + val.toString() + '%, #31A357), color-stop(' + val.toString() + '%, #727374))'
}

function updatePlaybackRate(value) {
function updatePlaybackRate (value) {
media.playbackRate(value)
}

function updatePlaybackRateSlider(volume) {
function updatePlaybackRateSlider (volume) {
var min = 0.5
var max = 4
var scaled = (volume.value - min) / (max - min)
var val = scaled * 100
volume.style.background = '-webkit-gradient(linear, left top, right top, color-stop(' + val.toString() + '%, #31A357), color-stop(' + val.toString() + '%, #727374))'
}

function defaultPlaybackRate () {
updatePlaybackRate(1)
var volume = $('#controls-pbrate-slider')[0]
volume.value = 1
updatePlaybackRateSlider(volume)
}

$('#controls-volume-slider').on('mousemove', function (e) {
if (isVolumeSliderClicked) {
var volume = $('#controls-volume-slider')[0]
Expand Down Expand Up @@ -281,6 +288,10 @@ $('#controls-pbrate-slider').on('mouseup', function (e) {
isPbrateSliderClicked = false
})

$('#controls-pbrate').on('dblclick', function () {
defaultPlaybackRate()
})

$(document).on('keydown', function (e) {
if (e.keyCode === 27 && isFullscreen) return onfullscreentoggle(e)
if (e.keyCode === 13 && e.metaKey) return onfullscreentoggle(e)
Expand Down Expand Up @@ -442,15 +453,15 @@ var appmenu_template = [
submenu: [
{
label: 'About Playback',
click: function() { ipc.send('open-url-in-external', 'https://mafintosh.github.io/playback/') }
click: function () { ipc.send('open-url-in-external', 'https://mafintosh.github.io/playback/') }
},
{
type: 'separator'
},
{
label: 'Quit',
accelerator: 'Command+Q',
click: function() { ipc.send('close') }
click: function () { ipc.send('close') }
}
]
},
Expand All @@ -460,7 +471,7 @@ var appmenu_template = [
{
label: 'Add media',
accelerator: 'Command+O',
click: function() { ipc.send('open-file-dialog') }
click: function () { ipc.send('open-file-dialog') }
},
{
label: 'Add link from clipboard',
Expand All @@ -475,7 +486,7 @@ var appmenu_template = [
{
label: 'Minimize',
accelerator: 'Command+M',
click: function() { ipc.send('minimize') }
click: function () { ipc.send('minimize') }
},
{
label: 'Toggle Full Screen',
Expand All @@ -489,18 +500,18 @@ var appmenu_template = [
submenu: [
{
label: 'Report Issue',
click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/issues') }
click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/issues') }
},
{
label: 'View Source Code on GitHub',
click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback') }
click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback') }
},
{
type: 'separator'
},
{
label: 'Releases',
click: function() { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/releases') }
click: function () { ipc.send('open-url-in-external', 'https://github.com/mafintosh/playback/releases') }
}
]
}
Expand Down Expand Up @@ -585,15 +596,15 @@ var server = http.createServer(function (req, res) {
var stringify = JSONStream.stringify()

var onseek = function () {
stringify.write({type: 'seek', time: media.time() })
stringify.write({ type: 'seek', time: media.time() })
}

var onsubs = function (data) {
stringify.write({type: 'subtitles', data: data.toString('base64')})
}

stringify.pipe(res)
stringify.write({type: 'open', url: 'http://' + network() + ':' + server.address().port + '/' + list.selected.id, time: media.time() })
stringify.write({ type: 'open', url: 'http://' + network() + ':' + server.address().port + '/' + list.selected.id, time: media.time() })

media.on('subtitles', onsubs)
media.on('seek', onseek)
Expand Down Expand Up @@ -640,7 +651,7 @@ server.listen(0, function () {
})

if (argv.follow) {
mdns.on('response', function onresponse(response) {
mdns.on('response', function onresponse (response) {
response.answers.forEach(function (a) {
if (a.name !== 'playback') return
clearInterval(interval)
Expand Down Expand Up @@ -701,17 +712,17 @@ server.listen(0, function () {
})

var volumeSlider = $('#controls-volume-slider')[0]
volumeSlider.setAttribute("value", 0.5)
volumeSlider.setAttribute("min", 0)
volumeSlider.setAttribute("max", 1)
volumeSlider.setAttribute("step", 0.05)
volumeSlider.setAttribute('value', 0.5)
volumeSlider.setAttribute('min', 0)
volumeSlider.setAttribute('max', 1)
volumeSlider.setAttribute('step', 0.05)
updateAudioVolume(0.5)
updateVolumeSlider(volumeSlider)

var pbrateSlider = $('#controls-pbrate-slider')[0]
pbrateSlider.setAttribute("value", 1)
pbrateSlider.setAttribute("min", 0.5)
pbrateSlider.setAttribute("max", 4)
pbrateSlider.setAttribute("step", 0.25)
pbrateSlider.setAttribute('value', 1)
pbrateSlider.setAttribute('min', 0.5)
pbrateSlider.setAttribute('max', 4)
pbrateSlider.setAttribute('step', 0.25)
updatePlaybackRate(1)
updatePlaybackRateSlider(pbrateSlider)
6 changes: 3 additions & 3 deletions player.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function ($video) {
$video.addEventListener('loadedmetadata', function () {
if (chromecast) return
that.width = $video.videoWidth
that.height = $video.videoHeight
that.height = $video.videoHeight
that.ratio = that.width / that.height
that.duration = $video.duration
that.emit('metadata')
Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = function ($video) {
var subsUrl = mediaUrl.replace(/(:\/\/.+)\/.*/, '$1/subtitles')
var subsList = []
for (var i = 0; i < 100; i++) subsList.push(subsUrl)
chromecast.play(mediaUrl, {title: 'Playback', seek: time || 0, subtitles: subsList, autoSubtitles: !!subs }, onmetadata)
chromecast.play(mediaUrl, { title: 'Playback', seek: time || 0, subtitles: subsList, autoSubtitles: !!subs }, onmetadata)
} else {
chromecast.resume()
}
Expand Down Expand Up @@ -164,7 +164,7 @@ module.exports = function ($video) {
if (!buf) return null
var $track = document.createElement('track')
$track.setAttribute('default', 'default')
$track.setAttribute('src', 'data:text/vtt;base64,'+buf.toString('base64'))
$track.setAttribute('src', 'data:text/vtt;base64,' + buf.toString('base64'))
$track.setAttribute('label', 'Subtitles')
$track.setAttribute('kind', 'subtitles')
$video.appendChild($track)
Expand Down
34 changes: 16 additions & 18 deletions playlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = function () {

torrent.files.forEach(function (f) {
if (/\.(vtt|srt)$/i.test(f.name)) {
subtitles[f.name] = f;
subtitles[f.name] = f
}
})

Expand All @@ -41,12 +41,11 @@ module.exports = function () {
var basename = f.name.substr(0, f.name.lastIndexOf('.'))
var subtitle = subtitles[basename + '.srt'] || subtitles[basename + '.vtt']
if (subtitle) {
subtitle.createReadStream().pipe(vtt()).pipe(concat(function(data) {
f.subtitles = data
subtitle.createReadStream().pipe(vtt()).pipe(concat(function (data) {
f.subtitles = data
}))
}
}

})

setInterval(function () {
Expand Down Expand Up @@ -111,22 +110,21 @@ module.exports = function () {
return +a.itag - +b.itag
})

var vidFmt
formats.forEach(function (fmt) {
// prefer webm
if (fmt.itag === '46') return vidFmt = fmt
if (fmt.itag === '45') return vidFmt = fmt
if (fmt.itag === '44') return vidFmt = fmt
if (fmt.itag === '43') return vidFmt = fmt
if (fmt.itag === '46') return (vidFmt = fmt)
if (fmt.itag === '45') return (vidFmt = fmt)
if (fmt.itag === '44') return (vidFmt = fmt)
if (fmt.itag === '43') return (vidFmt = fmt)

// otherwise h264
if (fmt.itag === '38') return vidFmt = fmt
if (fmt.itag === '37') return vidFmt = fmt
if (fmt.itag === '22') return vidFmt = fmt
if (fmt.itag === '18') return vidFmt = fmt
if (fmt.itag === '38') return (vidFmt = fmt)
if (fmt.itag === '37') return (vidFmt = fmt)
if (fmt.itag === '22') return (vidFmt = fmt)
if (fmt.itag === '18') return (vidFmt = fmt)
})

if (!vidFmt) return cb (new Error('No suitable video format found'))
if (!vidFmt) return cb(new Error('No suitable video format found'))

cb(null, {info: info, fmt: vidFmt})
})
Expand Down Expand Up @@ -157,9 +155,9 @@ module.exports = function () {
var ext = extensions.shift()
if (!ext) return ondone()

fs.exists(basename + '.' + ext, function(exists) {
fs.exists(basename + '.' + ext, function (exists) {
if (!exists) return next()
fs.createReadStream(basename + '.' + ext).pipe(vtt()).pipe(concat(function(data) {
fs.createReadStream(basename + '.' + ext).pipe(vtt()).pipe(concat(function (data) {
file.subtitles = data
ondone()
}))
Expand Down Expand Up @@ -199,11 +197,11 @@ module.exports = function () {
}

var onipfslink = function (link, cb) {
if (link[0] != '/') link = "/" + link // / may be stripped in add
if (link[0] !== '/') link = '/' + link // / may be stripped in add

var local = 'localhost:8080' // todo: make this configurable
var gateway = 'gateway.ipfs.io'
var file = {}
var file = { }

// first, try the local http gateway
var u = 'http://' + local + link
Expand Down
Binary file modified splash.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.