Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add trailer and revamp movie detail UI
- Loading branch information
Sing Ming Chen
committed
Nov 14, 2023
1 parent
a94d632
commit 4a761ca
Showing
10 changed files
with
435 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import * as React from 'react'; | ||
import * as Hls from 'hls.js'; | ||
|
||
class HLSVideoPlayer extends React.Component<{ streamUrl: string; poster: string }, {}> { | ||
videoRef = null; | ||
hls = null; | ||
|
||
componentDidMount() { | ||
this.initPlayer(); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (this.props.streamUrl !== prevProps.streamUrl) { | ||
this.initPlayer(); | ||
} | ||
} | ||
|
||
componentWillUnmount() { | ||
if (this.hls) { | ||
this.hls.destroy(); | ||
} | ||
} | ||
|
||
initPlayer() { | ||
if (Hls.isSupported()) { | ||
const video = this.videoRef; | ||
this.hls = new Hls(); | ||
this.hls.loadSource(this.props.streamUrl); | ||
this.hls.attachMedia(video); | ||
} | ||
} | ||
|
||
render() { | ||
return ( | ||
<video | ||
ref={(element) => { | ||
this.videoRef = element; | ||
}} | ||
poster={this.props.poster} | ||
controls | ||
width={'100%'} | ||
/> | ||
); | ||
} | ||
} | ||
|
||
export default HLSVideoPlayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.