1- import { useEffect , useState , useRef } from "react" ;
1+ import { useEffect , useRef } from "react" ;
22import styles from "./MediaViewer.module.css" ;
33import { AppsConfig , IMAGE_EXTENSIONS , VIDEO_EXTENSIONS , AUDIO_EXTENSIONS , useSystemManager , useWindowsManager , VirtualFile , WindowProps , MEDIA_EXTENSIONS } from "@prozilla-os/core" ;
44
@@ -9,7 +9,6 @@ export interface MediaViewerProps extends WindowProps {
99export function MediaViewer ( { file, close, setTitle } : MediaViewerProps ) {
1010 const { appsConfig } = useSystemManager ( ) ;
1111 const windowsManager = useWindowsManager ( ) ;
12- const [ isPlaying , setIsPlaying ] = useState ( false ) ;
1312 const audioRef = useRef < HTMLAudioElement | null > ( null ) ;
1413 const videoRef = useRef < HTMLVideoElement | null > ( null ) ;
1514
@@ -26,15 +25,13 @@ export function MediaViewer({ file, close, setTitle }: MediaViewerProps) {
2625 if ( audioRef . current ) {
2726 audioRef . current . src = file . source ;
2827 void audioRef . current . play ( ) ;
29- setIsPlaying ( true ) ;
3028 }
3129 }
3230
3331 if ( file . extension && VIDEO_EXTENSIONS . includes ( file . extension ) ) {
3432 if ( videoRef . current ) {
3533 videoRef . current . src = file . source ;
3634 void videoRef . current . play ( ) ;
37- setIsPlaying ( true ) ;
3835 }
3936 }
4037
@@ -50,38 +47,6 @@ export function MediaViewer({ file, close, setTitle }: MediaViewerProps) {
5047 } ;
5148 } , [ file ] ) ;
5249
53- const handlePlay = ( ) => {
54- if ( audioRef . current ) {
55- void audioRef . current . play ( ) ;
56- }
57- if ( videoRef . current ) {
58- void videoRef . current . play ( ) ;
59- }
60- setIsPlaying ( true ) ;
61- } ;
62-
63- const handlePause = ( ) => {
64- if ( audioRef . current ) {
65- audioRef . current . pause ( ) ;
66- }
67- if ( videoRef . current ) {
68- videoRef . current . pause ( ) ;
69- }
70- setIsPlaying ( false ) ;
71- } ;
72-
73- const handleStop = ( ) => {
74- if ( audioRef . current ) {
75- audioRef . current . pause ( ) ;
76- audioRef . current . currentTime = 0 ;
77- }
78- if ( videoRef . current ) {
79- videoRef . current . pause ( ) ;
80- videoRef . current . currentTime = 0 ;
81- }
82- setIsPlaying ( false ) ;
83- } ;
84-
8550 if ( file == null ) {
8651 const fileExplorerApp = appsConfig . getAppByRole ( AppsConfig . APP_ROLES . fileExplorer ) ;
8752
@@ -106,19 +71,10 @@ export function MediaViewer({ file, close, setTitle }: MediaViewerProps) {
10671 </ div > ;
10772 } else if ( AUDIO_EXTENSIONS . includes ( file . extension ) ) {
10873 return < div className = { styles . AudioViewer } >
109- < h3 > Playing audio: { file . id } </ h3 >
110- < audio ref = { audioRef } controls />
111- < div className = { styles . AudioControls } >
112- < button className = { isPlaying ? styles . Playing : "" } onClick = { handlePlay } disabled = { isPlaying } >
113- Play
114- </ button >
115- < button className = { isPlaying ? styles . Playing : "" } onClick = { handlePause } disabled = { ! isPlaying } >
116- Pause
117- </ button >
118- < button className = { isPlaying ? styles . Playing : "" } onClick = { handleStop } >
119- Stop
120- </ button >
121- </ div >
74+ < audio ref = { audioRef } controls >
75+ < source src = { file . source } type = { `video/${ file . extension } ` } />
76+ Your browser does not support audio.
77+ </ audio >
12278 </ div > ;
12379 } else if ( VIDEO_EXTENSIONS . includes ( file . extension ) ) {
12480 if ( file . extension === "yt" ) {
0 commit comments