2020-05-31 23:22:50 +02:00
|
|
|
import React from "react";
|
2020-07-08 00:14:08 +02:00
|
|
|
import style from "./Player.module.css"
|
2020-07-26 18:17:29 +02:00
|
|
|
|
2020-05-31 23:22:50 +02:00
|
|
|
import {PlyrComponent} from 'plyr-react';
|
2020-08-05 17:55:51 +00:00
|
|
|
import SideBar, {SideBarItem, SideBarTitle} from "../../elements/SideBar/SideBar";
|
2020-06-12 15:57:30 +00:00
|
|
|
import Tag from "../../elements/Tag/Tag";
|
|
|
|
import AddTagPopup from "../../elements/AddTagPopup/AddTagPopup";
|
2020-08-03 23:31:43 +00:00
|
|
|
import PageTitle, {Line} from "../../elements/PageTitle/PageTitle";
|
2020-05-31 23:22:50 +02:00
|
|
|
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* Player page loads when a video is selected to play and handles the video view
|
|
|
|
* and actions such as tag adding and liking
|
|
|
|
*/
|
2020-05-31 23:22:50 +02:00
|
|
|
class Player extends React.Component {
|
2020-06-01 19:09:32 +02:00
|
|
|
options = {
|
|
|
|
controls: [
|
|
|
|
'play-large', // The large play button in the center
|
|
|
|
'play', // Play/pause playback
|
|
|
|
'progress', // The progress bar and scrubber for playback and buffering
|
|
|
|
'current-time', // The current time of playback
|
|
|
|
'duration', // The full duration of the media
|
|
|
|
'mute', // Toggle mute
|
|
|
|
'volume', // Volume control
|
|
|
|
'captions', // Toggle captions
|
|
|
|
'settings', // Settings menu
|
|
|
|
'airplay', // Airplay (currently Safari only)
|
|
|
|
'download', // Show a download button with a link to either the current source or a custom URL you specify in your options
|
|
|
|
'fullscreen', // Toggle fullscreen
|
|
|
|
]
|
|
|
|
};
|
2020-05-31 23:22:50 +02:00
|
|
|
|
2020-08-05 17:55:51 +00:00
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
sources: null,
|
|
|
|
movie_id: null,
|
|
|
|
movie_name: null,
|
|
|
|
likes: null,
|
|
|
|
quality: null,
|
|
|
|
length: null,
|
|
|
|
tags: [],
|
2020-09-26 18:43:30 +00:00
|
|
|
suggesttag: [],
|
2020-08-05 17:55:51 +00:00
|
|
|
popupvisible: false
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:09:32 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.fetchMovieData();
|
2020-05-31 23:22:50 +02:00
|
|
|
}
|
|
|
|
|
2020-09-26 18:43:30 +00:00
|
|
|
/**
|
|
|
|
* quick add callback to add tag to db and change gui correctly
|
|
|
|
* @param tag_id id of tag to add
|
|
|
|
* @param tag_name name of tag to add
|
|
|
|
*/
|
|
|
|
quickAddTag(tag_id, tag_name) {
|
|
|
|
// save the tag
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'addTag');
|
|
|
|
updateRequest.append('id', tag_id);
|
|
|
|
updateRequest.append('movieid', this.props.movie_id);
|
|
|
|
|
|
|
|
fetch('/api/tags.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
if (result.result !== "success") {
|
|
|
|
console.error("error occured while writing to db -- todo error handling");
|
|
|
|
console.error(result.result);
|
|
|
|
} else {
|
|
|
|
// update tags if successful
|
|
|
|
let array = [...this.state.suggesttag]; // make a separate copy of the array
|
|
|
|
const index = array.map(function (e) {
|
|
|
|
return e.tag_id;
|
|
|
|
}).indexOf(tag_id);
|
|
|
|
|
|
|
|
if (index !== -1) {
|
|
|
|
array.splice(index, 1);
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
tags: [...this.state.tags, {tag_name: tag_name}],
|
|
|
|
suggesttag: array
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* generate sidebar with all items
|
|
|
|
*/
|
|
|
|
assembleSideBar() {
|
|
|
|
return (
|
|
|
|
<SideBar>
|
|
|
|
<SideBarTitle>Infos:</SideBarTitle>
|
|
|
|
<Line/>
|
|
|
|
<SideBarItem><b>{this.state.likes}</b> Likes!</SideBarItem>
|
|
|
|
{this.state.quality !== 0 ?
|
|
|
|
<SideBarItem><b>{this.state.quality}p</b> Quality!</SideBarItem> : null}
|
|
|
|
{this.state.length !== 0 ?
|
|
|
|
<SideBarItem><b>{Math.round(this.state.length / 60)}</b> Minutes of
|
|
|
|
length!</SideBarItem> : null}
|
|
|
|
<Line/>
|
|
|
|
<SideBarTitle>Tags:</SideBarTitle>
|
|
|
|
{this.state.tags.map((m) => (
|
|
|
|
<Tag
|
|
|
|
key={m.tag_name}
|
|
|
|
viewbinding={this.props.viewbinding}>{m.tag_name}</Tag>
|
|
|
|
))}
|
|
|
|
<Line/>
|
|
|
|
<SideBarTitle>Tag Quickadd:</SideBarTitle>
|
|
|
|
{this.state.suggesttag.map((m) => (
|
|
|
|
<Tag
|
|
|
|
key={m.tag_name}
|
|
|
|
onclick={() => {
|
|
|
|
this.quickAddTag(m.tag_id, m.tag_name);
|
|
|
|
}}>
|
|
|
|
{m.tag_name}
|
|
|
|
</Tag>
|
|
|
|
))}
|
|
|
|
</SideBar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-31 23:22:50 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2020-06-01 21:36:55 +02:00
|
|
|
<div id='videocontainer'>
|
2020-06-19 00:16:18 +02:00
|
|
|
<PageTitle
|
|
|
|
title='Watch'
|
|
|
|
subtitle={this.state.movie_name}/>
|
|
|
|
|
2020-09-26 18:43:30 +00:00
|
|
|
{this.assembleSideBar()}
|
2020-06-02 22:52:28 +02:00
|
|
|
|
2020-07-08 00:14:08 +02:00
|
|
|
<div className={style.videowrapper}>
|
2020-06-02 22:52:28 +02:00
|
|
|
{/* video component is added here */}
|
|
|
|
{this.state.sources ? <PlyrComponent
|
|
|
|
className='myvideo'
|
|
|
|
sources={this.state.sources}
|
|
|
|
options={this.options}/> :
|
|
|
|
<div>not loaded yet</div>}
|
2020-07-08 00:14:08 +02:00
|
|
|
<div className={style.videoactions}>
|
2020-06-02 22:52:28 +02:00
|
|
|
<button className='btn btn-primary' onClick={() => this.likebtn()}>Like this Video!</button>
|
2020-06-06 11:48:12 +00:00
|
|
|
<button className='btn btn-info' onClick={() => this.setState({popupvisible: true})}>Give this
|
|
|
|
Video a Tag
|
|
|
|
</button>
|
|
|
|
{this.state.popupvisible ?
|
|
|
|
<AddTagPopup show={this.state.popupvisible}
|
2020-06-07 23:27:31 +02:00
|
|
|
onHide={() => {
|
|
|
|
this.setState({popupvisible: false});
|
|
|
|
this.fetchMovieData();
|
|
|
|
}}
|
2020-06-06 11:48:12 +00:00
|
|
|
movie_id={this.state.movie_id}/> :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
2020-06-01 17:58:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-07-08 00:14:08 +02:00
|
|
|
<button className={style.closebutton} onClick={() => this.closebtn()}>Close</button>
|
2020-05-31 23:22:50 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-06-01 19:09:32 +02:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* fetch all the required infos of a video from backend
|
|
|
|
*/
|
2020-06-02 16:15:12 +02:00
|
|
|
fetchMovieData() {
|
2020-06-01 19:09:32 +02:00
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'loadVideo');
|
|
|
|
updateRequest.append('movieid', this.props.movie_id);
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
fetch('/api/video.php', {method: 'POST', body: updateRequest})
|
2020-06-01 19:09:32 +02:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((result) => {
|
|
|
|
this.setState({
|
|
|
|
sources: {
|
|
|
|
type: 'video',
|
|
|
|
sources: [
|
|
|
|
{
|
|
|
|
src: result.movie_url,
|
|
|
|
type: 'video/mp4',
|
|
|
|
size: 1080,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
poster: result.thumbnail
|
|
|
|
},
|
2020-06-06 11:48:12 +00:00
|
|
|
movie_id: result.movie_id,
|
2020-06-02 22:52:28 +02:00
|
|
|
movie_name: result.movie_name,
|
2020-06-02 16:15:12 +02:00
|
|
|
likes: result.likes,
|
|
|
|
quality: result.quality,
|
2020-06-03 12:26:10 +02:00
|
|
|
length: result.length,
|
2020-09-26 18:43:30 +00:00
|
|
|
tags: result.tags,
|
|
|
|
suggesttag: result.suggesttag
|
2020-06-01 19:09:32 +02:00
|
|
|
});
|
2020-09-26 18:43:30 +00:00
|
|
|
console.log(this.state);
|
2020-06-01 19:09:32 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* click handler for the like btn
|
|
|
|
*/
|
2020-06-01 19:09:32 +02:00
|
|
|
likebtn() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'addLike');
|
|
|
|
updateRequest.append('movieid', this.props.movie_id);
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
fetch('/api/video.php', {method: 'POST', body: updateRequest})
|
2020-06-12 15:57:30 +00:00
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
if (result.result === "success") {
|
2020-09-26 18:43:30 +00:00
|
|
|
// likes +1 --> avoid reload of all data
|
|
|
|
this.setState({likes: this.state.likes + 1})
|
2020-06-12 15:57:30 +00:00
|
|
|
} else {
|
2020-09-26 18:43:30 +00:00
|
|
|
console.error("an error occured while liking");
|
|
|
|
console.error(result);
|
2020-06-12 15:57:30 +00:00
|
|
|
}
|
|
|
|
}));
|
2020-06-01 19:09:32 +02:00
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* closebtn click handler
|
|
|
|
* calls callback to viewbinding to show previous page agains
|
|
|
|
*/
|
2020-06-01 19:09:32 +02:00
|
|
|
closebtn() {
|
2020-06-21 23:08:46 +02:00
|
|
|
this.props.viewbinding.returnToLastElement();
|
2020-06-01 19:09:32 +02:00
|
|
|
}
|
2020-05-31 23:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Player;
|