Skip to content

Commit

Permalink
feat(player): add video playback
Browse files Browse the repository at this point in the history
  • Loading branch information
heyhippari committed Oct 19, 2020
1 parent 371ff6e commit bfbd9f9
Show file tree
Hide file tree
Showing 20 changed files with 533 additions and 296 deletions.
134 changes: 134 additions & 0 deletions components/VideoPlayer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<template>
<v-container fill-height fluid class="pa-0">
<div ref="videoContainer">
<video ref="videoPlayer" :poster="poster" autoplay></video>
</div>
</v-container>
</template>

<script lang="ts">
import Vue from 'vue';
import { stringify } from 'qs';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import shaka from 'shaka-player/dist/shaka-player.ui';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import muxjs from 'mux.js';
import 'shaka-player/dist/controls.css';
declare global {
interface Window {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
muxjs: any;
}
}
export default Vue.extend({
props: {
item: {
type: Object,
required: true
},
poster: {
type: String,
default: ''
}
},
data() {
return {
source: '',
player: null as any,
ui: null as any
};
},
watch: {
async source(newSource) {
if (this.player) {
try {
await this.player.load(newSource);
} catch (e) {
console.error('Error code', e.code, 'object', e);
}
}
}
},
async mounted() {
try {
const response = await this.$api.mediaInfo.getPostedPlaybackInfo({
itemId: this.$route.params.itemId,
userId: this.$auth.user.Id,
deviceProfileDto: {
DeviceProfile: this.$playbackProfile
}
});
let mediaSource;
if (response?.data?.MediaSources) {
mediaSource = response.data.MediaSources[0];
} else {
throw new Error("This item can't be played.");
}
if (mediaSource.SupportsDirectStream) {
const directOptions: Record<string, any> = {
Static: true,
mediaSourceId: mediaSource.Id,
deviceId: this.$store.state.deviceProfile.deviceId,
api_key: this.$store.state.user.accessToken
};
if (mediaSource.ETag) {
directOptions.Tag = mediaSource.ETag;
}
if (mediaSource.LiveStreamId) {
directOptions.LiveStreamId = mediaSource.LiveStreamId;
}
const params = stringify(directOptions);
this.source = `${this.$axios.defaults.baseURL}/Videos/${mediaSource.Id}/stream.${mediaSource.Container}?${params}`;
} else if (
mediaSource.SupportsTranscoding &&
mediaSource.TranscodingUrl
) {
this.source = this.$axios.defaults.baseURL + mediaSource.TranscodingUrl;
}
window.muxjs = muxjs;
shaka.polyfill.installAll();
if (shaka.Player.isBrowserSupported()) {
// Everything looks good!
this.player = new shaka.Player(this.$refs.videoPlayer);
this.ui = new shaka.ui.Overlay(
this.player,
this.$refs.videoContainer,
this.$refs.videoPlayer
);
} else {
this.$nuxt.error({
message: this.$t('browserNotSupported') as string
});
}
} catch (error) {
this.$nuxt.error({
statusCode: 404,
message: error
});
}
},
beforeDestroy() {
if (this.player) {
window.muxjs = undefined;
this.player.unload();
this.player.destroy();
}
}
});
</script>

<style scoped>
video {
width: 100vw;
height: 100vh;
}
</style>
64 changes: 32 additions & 32 deletions locales/de.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"badRequest": "Fehlerhafte Anfrage. Erneut versuchen",
"continueListening": "Weiter zuhören",
"continueWatching": "Weiter anschauen",
"home": "Startseite",
"incorrectUsernameOrPassword": "Ungültiger Benutzername oder Passwort",
"login": "Anmelden",
"logout": "Abmelden",
"more": "Mehr",
"play": "Abspielen",
"serverAddressMustBeUrl": "Serveradresse muss eine gültige URL sein",
"serverAddressRequired": "Serveradresse ist erforderlich",
"serverNotFound": "Server nicht gefunden",
"settings": "Einstellungen",
"unexpectedError": "Unerwarteter Fehler",
"upNext": "Als nächstes",
"usernameRequired": "Benutzername erforderlich",
"signIn": "Anmelden",
"password": "Passwort",
"username": "Benutzername",
"serverAddress": "Serveradresse",
"itemNotFound": "Element nicht gefunden",
"libraryNotFound": "Bibliothek nicht gefunden",
"episodeNumber": "Episode {episodeNumber}",
"playType": "{mediaType} abspielen",
"moreLikeThis": "Ähnliches",
"present": "Jetzt",
"endsAt": "Endet um {time}",
"libraryEmpty": "Diese Bibliothek ist leer",
"rating": "Bewertung",
"endDate": "Enddatum",
"releaseDate": "Erscheinungsdatum",
"alphabetically": "Alphabetisch"
"badRequest": "Fehlerhafte Anfrage. Erneut versuchen",
"continueListening": "Weiter zuhören",
"continueWatching": "Weiter anschauen",
"home": "Startseite",
"incorrectUsernameOrPassword": "Ungültiger Benutzername oder Passwort",
"login": "Anmelden",
"logout": "Abmelden",
"more": "Mehr",
"play": "Abspielen",
"serverAddressMustBeUrl": "Serveradresse muss eine gültige URL sein",
"serverAddressRequired": "Serveradresse ist erforderlich",
"serverNotFound": "Server nicht gefunden",
"settings": "Einstellungen",
"unexpectedError": "Unerwarteter Fehler",
"upNext": "Als nächstes",
"usernameRequired": "Benutzername erforderlich",
"signIn": "Anmelden",
"password": "Passwort",
"username": "Benutzername",
"serverAddress": "Serveradresse",
"itemNotFound": "Element nicht gefunden",
"libraryNotFound": "Bibliothek nicht gefunden",
"episodeNumber": "Episode {episodeNumber}",
"playType": "{mediaType} abspielen",
"moreLikeThis": "Ähnliches",
"present": "Jetzt",
"endsAt": "Endet um {time}",
"libraryEmpty": "Diese Bibliothek ist leer",
"rating": "Bewertung",
"endDate": "Enddatum",
"releaseDate": "Erscheinungsdatum",
"alphabetically": "Alphabetisch"
}
10 changes: 4 additions & 6 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"endDate": "End date",
"rating": "Rating",
"badRequest": "Bad request. Try again",
"browserNotSupported": "This browser is not supported for playback.",
"continueListening": "Continue listening",
"continueWatching": "Continue watching",
"episodeNumber": "Episode {episodeNumber}",
Expand All @@ -16,17 +17,14 @@
"moreLikeThis": "More like this",
"play": "Play",
"present": "Present",
"playType": "Play {mediaType}",
"serverAddress": "Server address",
"serverAddressMustBeUrl": "Server address must be a valid URL",
"serverAddressRequired": "Server address is required",
"serverNotFound": "Server not found",
"settings": "Settings",
"unexpectedError": "Unexpected error",
"usernameRequired": "Username is required",
"serverAddress": "Server address",
"username": "Username",
"password": "Password",
"playType": "Play {mediaType}",
"signIn": "Sign in",
"unexpectedError": "Unexpected error",
"upNext": "Up next",
"libraryNotFound": "Library not found",
"itemNotFound": "Item not found",
Expand Down
64 changes: 32 additions & 32 deletions locales/fr-FR.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
{
"badRequest": "Mauvaise requête. Réessayez",
"continueListening": "Poursuivre l'écoute",
"continueWatching": "Poursuivre le visionnage",
"home": "Accueil",
"incorrectUsernameOrPassword": "Nom d'utilisateur ou mot de passe incorrect",
"login": "Connexion",
"logout": "Se déconnecter",
"more": "Plus",
"play": "Lire",
"serverAddressMustBeUrl": "L'adresse du serveur doit être une URL valide",
"serverAddressRequired": "L'adresse du serveur est requise",
"serverNotFound": "Serveur introuvable",
"settings": "Paramètres",
"unexpectedError": "Erreur inattendue",
"usernameRequired": "Nom d'utilisateur requis",
"serverAddress": "Adresse du serveur",
"username": "Nom d'utilisateur",
"password": "Mot de passe",
"signIn": "Se connecter",
"upNext": "À suivre",
"libraryNotFound": "Médiathèque introuvable",
"itemNotFound": "Élément introuvable",
"episodeNumber": "Épisode {episodeNumber}",
"playType": "Lire {mediaType}",
"present": "Maintenant",
"endsAt": "Se termine à {time}",
"moreLikeThis": "Similaires",
"libraryEmpty": "Cette médiathèque est vide",
"rating": "Critique",
"endDate": "Date de fin",
"releaseDate": "Date de sortie",
"alphabetically": "Alphabétique"
"badRequest": "Mauvaise requête. Réessayez",
"continueListening": "Poursuivre l'écoute",
"continueWatching": "Poursuivre le visionnage",
"home": "Accueil",
"incorrectUsernameOrPassword": "Nom d'utilisateur ou mot de passe incorrect",
"login": "Connexion",
"logout": "Se déconnecter",
"more": "Plus",
"play": "Lire",
"serverAddressMustBeUrl": "L'adresse du serveur doit être une URL valide",
"serverAddressRequired": "L'adresse du serveur est requise",
"serverNotFound": "Serveur introuvable",
"settings": "Paramètres",
"unexpectedError": "Erreur inattendue",
"usernameRequired": "Nom d'utilisateur requis",
"serverAddress": "Adresse du serveur",
"username": "Nom d'utilisateur",
"password": "Mot de passe",
"signIn": "Se connecter",
"upNext": "À suivre",
"libraryNotFound": "Médiathèque introuvable",
"itemNotFound": "Élément introuvable",
"episodeNumber": "Épisode {episodeNumber}",
"playType": "Lire {mediaType}",
"present": "Maintenant",
"endsAt": "Se termine à {time}",
"moreLikeThis": "Similaires",
"libraryEmpty": "Cette médiathèque est vide",
"rating": "Critique",
"endDate": "Date de fin",
"releaseDate": "Date de sortie",
"alphabetically": "Alphabétique"
}
54 changes: 27 additions & 27 deletions locales/nl.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"badRequest": "Onjuist verzoek. Probeer het opnieuw",
"continueListening": "Verder luisteren",
"continueWatching": "Verder kijken",
"home": "Home",
"incorrectUsernameOrPassword": "Onjuiste gebruikersnaam en/of wachtwoord",
"login": "Inloggen",
"logout": "Uitloggen",
"more": "Meer",
"play": "Afspelen",
"serverAddressMustBeUrl": "Server adres moet een geldige URL zijn",
"serverAddressRequired": "Server adres is verplicht",
"serverNotFound": "Server niet gevonden",
"settings": "Instellingen",
"unexpectedError": "Onverwachte fout",
"upNext": "Volgende",
"usernameRequired": "Gebruikersnaam is verplicht",
"itemNotFound": "Item niet gevonden",
"libraryNotFound": "Bibliotheek niet gevonden",
"signIn": "Inloggen",
"password": "Wachtwoord",
"username": "Gebruikersnaam",
"serverAddress": "Server adres",
"episodeNumber": "Aflevering {episodeNumber}",
"playType": "Speel {mediaType}",
"present": "Huidig",
"moreLikeThis": "Meer zoals dit",
"endsAt": "Eindigt om {time}"
"badRequest": "Onjuist verzoek. Probeer het opnieuw",
"continueListening": "Verder luisteren",
"continueWatching": "Verder kijken",
"home": "Home",
"incorrectUsernameOrPassword": "Onjuiste gebruikersnaam en/of wachtwoord",
"login": "Inloggen",
"logout": "Uitloggen",
"more": "Meer",
"play": "Afspelen",
"serverAddressMustBeUrl": "Server adres moet een geldige URL zijn",
"serverAddressRequired": "Server adres is verplicht",
"serverNotFound": "Server niet gevonden",
"settings": "Instellingen",
"unexpectedError": "Onverwachte fout",
"upNext": "Volgende",
"usernameRequired": "Gebruikersnaam is verplicht",
"itemNotFound": "Item niet gevonden",
"libraryNotFound": "Bibliotheek niet gevonden",
"signIn": "Inloggen",
"password": "Wachtwoord",
"username": "Gebruikersnaam",
"serverAddress": "Server adres",
"episodeNumber": "Aflevering {episodeNumber}",
"playType": "Speel {mediaType}",
"present": "Huidig",
"moreLikeThis": "Meer zoals dit",
"endsAt": "Eindigt om {time}"
}
Loading

0 comments on commit bfbd9f9

Please sign in to comment.