Skip to content

Commit a1e0a35

Browse files
committed
media-viewer: Updated audio player
1 parent f2fea89 commit a1e0a35

File tree

5 files changed

+10
-83
lines changed

5 files changed

+10
-83
lines changed
3.76 MB
Binary file not shown.
3.33 MB
Binary file not shown.

packages/apps/media-viewer/src/components/MediaViewer.module.css

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,9 @@
1111
width: 100%;
1212
height: 100%;
1313
object-fit: contain;
14-
}
15-
16-
.AudioViewer {
17-
width: 70%;
18-
margin: 0.5rem auto 0;
19-
}
20-
21-
.AudioViewer .AudioControls {
22-
margin-top: 20px;
23-
display: flex;
24-
justify-content: center;
25-
align-items: center;
26-
}
27-
28-
.AudioControls button {
29-
margin: 1rem;
30-
padding: 0.5rem 0;
31-
width: 20%;
32-
border-radius: var(--border-radius-1);
33-
}
34-
35-
.AudioControls > .Playing {
36-
background-color: var(--purple-0);
37-
color: var(--white-0);
38-
}
39-
40-
.AudioControls > :not(.Playing) {
41-
background-color: var(--red-0);
42-
color: var(--white-0);
4314
}
4415

45-
.VideoViewer {
16+
.VideoViewer, .AudioViewer {
4617
display: flex;
4718
flex-direction: column;
4819
align-items: center;

packages/apps/media-viewer/src/components/MediaViewer.tsx

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState, useRef } from "react";
1+
import { useEffect, useRef } from "react";
22
import styles from "./MediaViewer.module.css";
33
import { 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 {
99
export 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") {

packages/core/src/features/virtual-drive/root/defaultData.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ export function loadDefaultData(systemManager: SystemManager, virtualRoot: Virtu
121121

122122
userFolder.createFolder("Audio", (folder) => {
123123
folder.setIconUrl(skin.folderIcons.audio ?? skin.folderIcons.generic)
124-
.createFile("Assasins Creed Rogue Theme", "mp3", (file) => {
125-
file.setSource("https://vgmsite.com/soundtracks/assassin-s-creed-rogue-original-game-soundtrack/rgvmdtdtyv/01.%20Assassin%27s%20Creed%20Rogue%20Main%20Theme.mp3");
124+
.createFile("Andrew-Applepie_Im-So", "ogg", (file) => {
125+
file.setSource("/assets/audio/Andrew-Applepie_Im-So.ogg");
126126
})
127-
.createFile("Mortal Kombat theme", "mp3", (file) => {
128-
file.setSource("https://kappa.vgmsite.com/soundtracks/mortal-kombat-vscdt-1487-1993/posqvhcduj/01.%20TECHNO-SYNDROME%207%27%27%20MIX.mp3");
127+
.createFile("Andrew-Applepie_Run-Part-2", "ogg", (file) => {
128+
file.setSource("/assets/audio/Andrew-Applepie_Run-Part-2.ogg");
129129
});
130130
});
131131

0 commit comments

Comments
 (0)