Last active
March 17, 2025 13:11
-
-
Save davekiss/eae7c82824929826c4066b37db86474e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Simple player (React) | |
import { | |
MediaController, | |
MediaControlBar, | |
MediaTimeRange, | |
MediaTimeDisplay, | |
MediaVolumeRange, | |
MediaPlayButton, | |
MediaSeekBackwardButton, | |
MediaSeekForwardButton, | |
MediaMuteButton, | |
} from 'media-chrome/react'; | |
const SimplePlayer = () => { | |
return ( | |
<MediaController> | |
<video | |
slot="media" | |
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4" | |
preload="auto" | |
muted | |
/> | |
<MediaControlBar> | |
<MediaPlayButton></MediaPlayButton> | |
<MediaSeekBackwardButton></MediaSeekBackwardButton> | |
<MediaSeekForwardButton></MediaSeekForwardButton> | |
<MediaTimeRange></MediaTimeRange> | |
<MediaTimeDisplay showDuration></MediaTimeDisplay> | |
<MediaMuteButton></MediaMuteButton> | |
<MediaVolumeRange></MediaVolumeRange> | |
</MediaControlBar> | |
</MediaController> | |
); | |
}; | |
export default SimplePlayer; | |
// Controlling a player (React) | |
import { MediaController } from 'media-chrome/react'; | |
import { useRef } from 'react'; | |
interface PlayerProps { | |
isPlaying: boolean; | |
} | |
const Player = ({ isPlaying }: PlayerProps) => { | |
const videoRef = useRef<HTMLVideoElement>(null); | |
const togglePlay = () => { | |
if (videoRef.current) { | |
if (isPlaying) { | |
videoRef.current.pause(); | |
} else { | |
videoRef.current.play(); | |
} | |
} | |
} | |
return ( | |
<> | |
<button onClick={togglePlay}>{isPlaying ? 'Pause' : 'Play'}</button> | |
<MediaController id="player"> | |
<video | |
slot="media" | |
ref={videoRef} | |
src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4" | |
preload="auto" | |
muted | |
/> | |
</MediaController> | |
</> | |
); | |
}; | |
export default Player; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment