Skip to content

Commit

Permalink
Adding audio support #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Raúl C. Rivero committed Jul 4, 2019
1 parent c586bfb commit 4555084
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
6 changes: 5 additions & 1 deletion public/styles/media.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@
height: 90vh;
}

.page video:focus{
.page video:focus, .page audio:focus{
outline: none;
}

.page audio {
width: 100%;
}

@media only screen and (max-device-width: 824px) {
.page {
font-size: 30px;
Expand Down
12 changes: 10 additions & 2 deletions routes/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ router.get('/video/:dir_id/', (req, res) => {
}
return array;
}, []);

const fileUrl = '/api/media/' + req.params['dir_id'] + '/?subdir=' + subdir;
const mimeType = mime.lookup(fileUrl);
if(mimeType.includes("video"))
mediaType = 'video';
else if(mimeType.includes("audio"))
mediaType = 'audio';

res.render('media', {
videoUrl: '/api/media/' + req.params['dir_id'] + '/?subdir=' + subdir,
Url: fileUrl,
type: mediaType,
subtitles,
title: path.basename(subdir)
});
Expand Down Expand Up @@ -59,7 +67,7 @@ router.get('/:dir_id/', (req, res) => {
const files = dirs.reduce((array, filePath) => {
try {
const mimeType = mime.lookup(filePath);
if (fs.statSync(filePath).isFile() && mimeType && mimeType.includes("video")) {
if (fs.statSync(filePath).isFile() && mimeType && (mimeType.includes("video") || mimeType.includes("audio"))) {
array.push({
url: '/media/video/' + req.params['dir_id'] + '?subdir=' + path.join(subdir, path.basename(filePath)),
name: path.basename(filePath)
Expand Down
10 changes: 7 additions & 3 deletions views/media.pug
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ block styles
block content
div(class='page')
h1= title
video(controls src=videoUrl)
each subtitle in subtitles
track(src=subtitle.url label=subtitle.label)
if type == 'video'
video(controls src=Url)
each subtitle in subtitles
track(src=subtitle.url label=subtitle.label)
else
audio(controls src=Url)

0 comments on commit 4555084

Please sign in to comment.