Implement autoplay of videos.

This commit is contained in:
FireMasterK 2020-12-10 13:23:30 +05:30
parent e9d1a77a6a
commit e2f0892269
No known key found for this signature in database
GPG key ID: 8DFF5DD33E93DB58
2 changed files with 24 additions and 0 deletions

View file

@ -1,3 +1,4 @@
export default { export default {
BASE_URL: localStorage.getItem("instance") || 'https://pipedapi.kavin.rocks', BASE_URL: localStorage.getItem("instance") || 'https://pipedapi.kavin.rocks',
AUTO_PLAY: localStorage.getItem("autoplay") || false
} }

View file

@ -33,6 +33,14 @@
<hr /> <hr />
<b>Auto Play next Video:</b>&nbsp;
<input
class="uk-checkbox"
v-model="selectedAutoPlay"
@change="onChange($event)"
type="checkbox"
/>
<div <div
class="uk-tile-default uk-text-secondary" class="uk-tile-default uk-text-secondary"
style="background: #0b0e0f; width: 300px" style="background: #0b0e0f; width: 300px"
@ -80,6 +88,7 @@ export default {
mounted() { mounted() {
this.getVideoData(); this.getVideoData();
this.getSponsors(); this.getSponsors();
this.selectedAutoPlay = Constants.AUTO_PLAY;
}, },
beforeUnmount() { beforeUnmount() {
if (this.player) { if (this.player) {
@ -116,6 +125,10 @@ export default {
) )
).json(); ).json();
}, },
onChange() {
if (localStorage)
localStorage.setItem("autoplay", this.selectedAutoPlay);
},
async getVideoData() { async getVideoData() {
this.fetchVideo() this.fetchVideo()
.then(data => (this.video = data)) .then(data => (this.video = data))
@ -246,6 +259,16 @@ export default {
this.player.on("volumechange", () => { this.player.on("volumechange", () => {
this.audioplayer.volume = this.player.volume(); this.audioplayer.volume = this.player.volume();
}); });
this.player.on("ended", () => {
if (
this.selectedAutoPlay &&
this.video.relatedStreams.length > 0
)
this.$router.push(
this.video.relatedStreams[0].url
);
});
} }
if (!noPrevPlayer) if (!noPrevPlayer)