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-06-03 12:26:10 +02:00
|
|
|
import Tag from "./Tag";
|
2020-06-06 11:48:12 +00:00
|
|
|
import AddTagPopup from "./AddTagPopup";
|
2020-05-31 23:22:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Player extends React.Component {
|
|
|
|
constructor(props, context) {
|
|
|
|
super(props, context);
|
|
|
|
|
2020-06-03 12:26:10 +02:00
|
|
|
this.state = {
|
|
|
|
sources: null,
|
2020-06-06 11:48:12 +00:00
|
|
|
movie_id: null,
|
2020-06-03 12:26:10 +02:00
|
|
|
movie_name: null,
|
|
|
|
likes: null,
|
|
|
|
quality: null,
|
|
|
|
length: null,
|
2020-06-06 11:48:12 +00:00
|
|
|
tags: [],
|
|
|
|
popupvisible: false
|
2020-06-03 12:26:10 +02:00
|
|
|
};
|
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>
|
2020-06-06 11:48:12 +00:00
|
|
|
{this.state.quality !== 0 ?
|
2020-06-04 22:19:18 +02:00
|
|
|
<div className='sidebarinfo'><b>{this.state.quality}p</b> Quality!
|
|
|
|
</div> : null}
|
2020-06-06 11:48:12 +00:00
|
|
|
{this.state.length !== 0 ?
|
2020-06-04 22:19:18 +02:00
|
|
|
<div className='sidebarinfo'><b>{Math.round(this.state.length / 60)}</b> Minutes of length!
|
|
|
|
</div> : null}
|
2020-06-02 22:52:28 +02:00
|
|
|
<hr/>
|
|
|
|
<div className='sidebartitle'>Tags:</div>
|
2020-06-03 12:26:10 +02:00
|
|
|
{this.state.tags.map((m) => (
|
|
|
|
<Tag>{m.tag_name}</Tag>
|
|
|
|
))}
|
2020-06-02 22:52:28 +02:00
|
|
|
</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>
|
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}
|
|
|
|
onHide={() => this.setState({popupvisible: false})}
|
|
|
|
movie_id={this.state.movie_id}/> :
|
|
|
|
null
|
|
|
|
}
|
|
|
|
|
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-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,
|
|
|
|
tags: result.tags
|
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;
|