Unverified Commit 748cc51c authored by Thuy Doan's avatar Thuy Doan Committed by GitHub

Update with-mux-video to use latest upchunk and replace video player with mux-player-react (#37621)

* Update upchunk to latest (2.3.1).

* Add mux-player package to package.json

* WIP: Make VideoPlayer return mux-player

* Remove unused code from prev video player

* Use mux-player-react directly

* Fix import line for mux-player-react

* chore: fix lint issues
parent b33bc2df
import { useEffect, useRef } from 'react'
import Hls from 'hls.js'
export default function VideoPlayer({ src, poster }) {
const videoRef = useRef(null)
useEffect(() => {
const video = videoRef.current
if (!video) return
video.controls = true
let hls
if (video.canPlayType('application/vnd.apple.mpegurl')) {
// This will run in safari, where HLS is supported natively
video.src = src
} else if (Hls.isSupported()) {
// This will run in all other modern browsers
hls = new Hls()
hls.loadSource(src)
hls.attachMedia(video)
} else {
console.error(
'This is an old browser that does not support MSE https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API'
)
}
return () => {
if (hls) {
hls.destroy()
}
}
}, [src, videoRef])
return (
<>
<video ref={videoRef} poster={poster} />
<style jsx>{`
video {
width: 800px;
max-width: 100%;
cursor: pointer;
padding-top: 40px;
padding-bottom: 40px;
}
`}</style>
</>
)
}
...@@ -7,8 +7,8 @@ ...@@ -7,8 +7,8 @@
}, },
"dependencies": { "dependencies": {
"@mux/mux-node": "^2.8.0", "@mux/mux-node": "^2.8.0",
"@mux/upchunk": "^2.0.0", "@mux-elements/mux-player-react": "0.1.0-beta.19",
"hls.js": "^0.13.2", "@mux/upchunk": "^2.3.1",
"next": "latest", "next": "latest",
"react": "^17.0.2", "react": "^17.0.2",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
......
import MuxPlayer from '@mux-elements/mux-player-react'
import Link from 'next/link' import Link from 'next/link'
import Layout from '../../components/layout' import Layout from '../../components/layout'
import VideoPlayer from '../../components/video-player'
import Spinner from '../../components/spinner' import Spinner from '../../components/spinner'
import { MUX_HOME_PAGE_URL } from '../../constants' import { MUX_HOME_PAGE_URL } from '../../constants'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
export function getStaticProps({ params: { id: playbackId } }) { export function getStaticProps({ params: { id: playbackId } }) {
const src = `https://stream.mux.com/${playbackId}.m3u8`
const poster = `https://image.mux.com/${playbackId}/thumbnail.png` const poster = `https://image.mux.com/${playbackId}/thumbnail.png`
return { props: { playbackId, src, poster } } return { props: { playbackId, poster } }
} }
export function getStaticPaths() { export function getStaticPaths() {
...@@ -33,7 +32,7 @@ const Code = ({ children }) => ( ...@@ -33,7 +32,7 @@ const Code = ({ children }) => (
</> </>
) )
export default function Playback({ playbackId, src, poster }) { export default function Playback({ playbackId, poster }) {
const router = useRouter() const router = useRouter()
if (router.isFallback) { if (router.isFallback) {
...@@ -51,7 +50,7 @@ export default function Playback({ playbackId, src, poster }) { ...@@ -51,7 +50,7 @@ export default function Playback({ playbackId, src, poster }) {
loadTwitterWidget loadTwitterWidget
> >
<div className="flash-message">This video is ready for playback</div> <div className="flash-message">This video is ready for playback</div>
<VideoPlayer src={src} poster={poster} /> <MuxPlayer style={{ width: '100%' }} playbackId={playbackId} />
<p> <p>
Go{' '} Go{' '}
<Link href="/"> <Link href="/">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment