Skip to content

Instantly share code, notes, and snippets.

@davekiss
Last active March 17, 2025 13:11
Show Gist options
  • Save davekiss/eae7c82824929826c4066b37db86474e to your computer and use it in GitHub Desktop.
Save davekiss/eae7c82824929826c4066b37db86474e to your computer and use it in GitHub Desktop.
// 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