-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] HlsPlayer를 사용해 방송화면에 실시간 스트리밍 화면 연결 (#162)
* feat : id props로 추가 및 css스타일 변경 * feat : 방송 화면에 HlsPlayer 추가 * feat : 환경변수에 HLS_URL 추가
- Loading branch information
1 parent
7c105f2
commit f19e4b7
Showing
4 changed files
with
49 additions
and
20 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
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 |
---|---|---|
@@ -1,32 +1,55 @@ | ||
import { useEffect, useRef } from 'react'; | ||
import Hls from 'hls.js'; | ||
import { useEffect, useRef } from 'react' | ||
import Hls from 'hls.js' | ||
import styled from 'styled-components' | ||
|
||
const HlsPlayer = () => { | ||
const videoSrc = 'https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8'; | ||
const videoRef = useRef<HTMLVideoElement>(null); | ||
interface HlsPlayerProps { | ||
id?: string | ||
} | ||
|
||
useEffect(() => { | ||
const video = videoRef.current; | ||
let hls:Hls; | ||
const HlsPlayer = ({ id }: HlsPlayerProps) => { | ||
const videoSrc = `${import.meta.env.VITE_HLS_URL}/${id}` | ||
const videoRef = useRef<HTMLVideoElement>(null) | ||
|
||
useEffect(() => { | ||
const video = videoRef.current | ||
let hls: Hls | ||
console.log(videoSrc) | ||
if (video) { | ||
if (video.canPlayType('application/vnd.apple.mpegurl')) { | ||
video.src = videoSrc; | ||
video.src = videoSrc | ||
} else if (Hls.isSupported()) { | ||
hls = new Hls(); | ||
hls.loadSource(videoSrc); | ||
hls.attachMedia(video); | ||
hls = new Hls() | ||
hls.loadSource(videoSrc) | ||
hls.attachMedia(video) | ||
} | ||
|
||
return () => { | ||
if (hls) { | ||
hls.destroy(); | ||
hls.destroy() | ||
} | ||
}; | ||
} | ||
} | ||
}, []); | ||
}, []) | ||
|
||
return ( | ||
<Container> | ||
<Video ref={videoRef} controls /> | ||
</Container> | ||
) | ||
} | ||
|
||
export default HlsPlayer | ||
|
||
return <video ref={videoRef} controls />; | ||
}; | ||
const Container = styled.div` | ||
position: relative; | ||
padding-bottom: 56.25%; | ||
padding-top: 9rem; | ||
` | ||
|
||
export default HlsPlayer; | ||
const Video = styled.video` | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
` |
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