2020-05-31 23:22:50 +02:00
|
|
|
import React from "react";
|
|
|
|
import "./css/Player.css"
|
|
|
|
import {PlyrComponent} from 'plyr-react';
|
2020-06-02 22:52:28 +02:00
|
|
|
import SideBar from "./SideBar";
|
2020-05-31 23:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Player extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
2020-06-01 19:09:32 +02:00
|
|
|
this.state = {};
|
2020-05-31 23:22:50 +02:00
|
|
|
|
|
|
|
this.props = props;
|
|
|
|
}
|
|
|
|
|
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-06-01 19:09:32 +02:00
|
|
|
componentDidMount() {
|
|
|
|
this.fetchMovieData();
|
2020-05-31 23:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2020-06-01 21:36:55 +02:00
|
|
|
<div id='videocontainer'>
|
2020-06-02 22:52:28 +02:00
|
|
|
<div className='pageheader'>
|
|
|
|
<span className='pageheadertitle'>Watch</span>
|
|
|
|
<span className='pageheadersubtitle'>{this.state.movie_name}</span>
|
|
|
|
<hr/>
|
2020-06-01 17:58:48 +02:00
|
|
|
</div>
|
2020-06-02 22:52:28 +02:00
|
|
|
<SideBar>
|
|
|
|
<div className='sidebartitle'>Infos:</div>
|
|
|
|
<hr/>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.likes}</b> Likes!</div>
|
|
|
|
<div className='sidebarinfo'><b> {this.state.quality}p</b> Quality!</div>
|
|
|
|
<div className='sidebarinfo'><b>{this.state.length}</b> Minutes of length!</div>
|
|
|
|
<hr/>
|
|
|
|
<div className='sidebartitle'>Tags:</div>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("all")}>All</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("fullhd")}>FullHd</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("lowquality")}>LowQuality</button>
|
|
|
|
<button className='tagbtn' onClick={() => this.fetchVideoData("hd")}>HD</button>
|
|
|
|
</SideBar>
|
|
|
|
|
|
|
|
<div className="videowrapper">
|
|
|
|
{/* video component is added here */}
|
|
|
|
{this.state.sources ? <PlyrComponent
|
|
|
|
className='myvideo'
|
|
|
|
sources={this.state.sources}
|
|
|
|
options={this.options}/> :
|
|
|
|
<div>not loaded yet</div>}
|
|
|
|
<div className='videoactions'>
|
|
|
|
<button className='btn btn-primary' onClick={() => this.likebtn()}>Like this Video!</button>
|
|
|
|
<button className='btn btn-info' id="tagbutton">Give this Video a Tag</button>
|
2020-06-01 17:58:48 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2020-06-02 22:52:28 +02:00
|
|
|
<button className="closebutton" onClick={() => this.closebtn()}>Close</button>
|
2020-05-31 23:22:50 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-06-01 19:09:32 +02:00
|
|
|
|
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-06-01 21:36:55 +02:00
|
|
|
fetch('/api/videoload.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-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,
|
|
|
|
length: result.length
|
2020-06-01 19:09:32 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Click Listener */
|
|
|
|
likebtn() {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
updateRequest.append('action', 'addLike');
|
|
|
|
updateRequest.append('movieid', this.props.movie_id);
|
|
|
|
|
2020-06-01 21:36:55 +02:00
|
|
|
fetch('/api/videoload.php', {method: 'POST', body: updateRequest})
|
2020-06-01 19:09:32 +02:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((result) => {
|
2020-06-02 16:15:12 +02:00
|
|
|
if (result.result === "success") {
|
2020-06-01 19:09:32 +02:00
|
|
|
this.fetchMovieData();
|
2020-06-02 16:15:12 +02:00
|
|
|
} else {
|
2020-06-01 19:09:32 +02:00
|
|
|
console.log("an error occured while liking");
|
|
|
|
console.log(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
closebtn() {
|
|
|
|
this.props.viewbinding.hideVideo();
|
|
|
|
}
|
2020-05-31 23:22:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Player;
|