2021-10-22 19:30:09 +00:00
|
|
|
import {
|
2021-11-02 16:20:47 +00:00
|
|
|
MediaSet,
|
|
|
|
GrpcWebImpl,
|
|
|
|
MediaSetServiceClientImpl,
|
2021-11-20 18:29:34 +00:00
|
|
|
GetVideoProgress,
|
2021-12-17 16:30:53 +00:00
|
|
|
GetPeaksProgress,
|
2021-11-02 16:20:47 +00:00
|
|
|
} from './generated/media_set';
|
2021-10-29 12:52:31 +00:00
|
|
|
|
2021-12-04 04:34:17 +00:00
|
|
|
import { useState, useEffect, useRef, useCallback } from 'react';
|
2021-12-29 15:38:25 +00:00
|
|
|
import { AudioFormat } from './generated/media_set';
|
2021-10-08 14:38:35 +00:00
|
|
|
import { VideoPreview } from './VideoPreview';
|
2021-11-29 17:44:31 +00:00
|
|
|
import { Overview, CanvasLogicalWidth } from './Overview';
|
2021-10-08 14:38:35 +00:00
|
|
|
import { Waveform } from './Waveform';
|
|
|
|
import { ControlBar } from './ControlBar';
|
|
|
|
import { SeekBar } from './SeekBar';
|
2021-11-30 19:41:34 +00:00
|
|
|
import { firstValueFrom, from, Observable } from 'rxjs';
|
|
|
|
import { first, map } from 'rxjs/operators';
|
2022-01-01 23:26:10 +00:00
|
|
|
import millisFromDuration from './helpers/millisFromDuration';
|
2022-01-16 07:58:07 +00:00
|
|
|
import { zoomViewportIn, zoomViewportOut } from './helpers/zoom';
|
2021-09-06 14:25:23 +00:00
|
|
|
|
2022-01-14 11:54:54 +00:00
|
|
|
import { ExternalLinkIcon } from '@heroicons/react/solid';
|
|
|
|
|
2021-11-02 16:20:47 +00:00
|
|
|
// ported from backend, where should they live?
|
2022-01-14 11:54:54 +00:00
|
|
|
const thumbnailWidth = 177; // height 100
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2021-12-06 22:52:24 +00:00
|
|
|
const initialViewportCanvasPixels = 100;
|
2021-11-17 17:53:27 +00:00
|
|
|
|
2022-01-16 07:58:07 +00:00
|
|
|
const zoomFactor = 2;
|
|
|
|
|
2021-11-27 13:26:14 +00:00
|
|
|
const apiURL = process.env.REACT_APP_API_URL || 'http://localhost:8888';
|
|
|
|
|
2021-12-11 16:25:43 +00:00
|
|
|
// Frames represents a range of audio frames.
|
2021-10-08 14:38:35 +00:00
|
|
|
export interface Frames {
|
|
|
|
start: number;
|
|
|
|
end: number;
|
|
|
|
}
|
2021-09-06 10:17:50 +00:00
|
|
|
|
2021-11-25 18:02:37 +00:00
|
|
|
export interface VideoPosition {
|
|
|
|
currentTime: number;
|
|
|
|
percent: number;
|
|
|
|
}
|
|
|
|
|
2022-01-14 11:54:54 +00:00
|
|
|
export enum PlayState {
|
|
|
|
Paused,
|
|
|
|
Playing,
|
|
|
|
}
|
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
const video = document.createElement('video');
|
|
|
|
const audio = document.createElement('audio');
|
|
|
|
|
2021-09-30 19:08:48 +00:00
|
|
|
function App(): JSX.Element {
|
2021-10-08 14:38:35 +00:00
|
|
|
const [mediaSet, setMediaSet] = useState<MediaSet | null>(null);
|
2021-12-11 16:25:43 +00:00
|
|
|
const [viewport, setViewport] = useState<Frames>({ start: 0, end: 0 });
|
|
|
|
const [selection, setSelection] = useState<Frames>({ start: 0, end: 0 });
|
2021-11-29 17:44:31 +00:00
|
|
|
const [overviewPeaks, setOverviewPeaks] = useState<Observable<number[]>>(
|
|
|
|
from([])
|
|
|
|
);
|
2022-01-14 11:54:54 +00:00
|
|
|
const [playState, setPlayState] = useState(PlayState.Paused);
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
// position stores the current playback position. positionRef makes it
|
|
|
|
// available inside a setInterval callback.
|
|
|
|
const [position, setPosition] = useState({ currentTime: 0, percent: 0 });
|
|
|
|
const positionRef = useRef(position);
|
|
|
|
positionRef.current = position;
|
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
// effects
|
|
|
|
|
|
|
|
// TODO: error handling
|
|
|
|
const videoID = new URLSearchParams(window.location.search).get('video_id');
|
2021-10-22 19:30:09 +00:00
|
|
|
if (videoID == null) {
|
|
|
|
return <></>;
|
|
|
|
}
|
2021-10-08 14:38:35 +00:00
|
|
|
|
|
|
|
// fetch mediaset on page load:
|
|
|
|
useEffect(() => {
|
|
|
|
(async function () {
|
2021-11-04 06:13:00 +00:00
|
|
|
const rpc = newRPC();
|
2021-11-02 16:20:47 +00:00
|
|
|
const service = new MediaSetServiceClientImpl(rpc);
|
|
|
|
const mediaSet = await service.Get({ youtubeId: videoID });
|
2021-10-22 19:30:09 +00:00
|
|
|
|
2021-10-29 12:52:31 +00:00
|
|
|
console.log('got media set:', mediaSet);
|
2021-11-02 16:20:47 +00:00
|
|
|
setMediaSet(mediaSet);
|
2021-10-08 14:38:35 +00:00
|
|
|
})();
|
|
|
|
}, []);
|
|
|
|
|
2022-01-15 08:44:12 +00:00
|
|
|
const updatePlayerPositionIntevalMillis = 20;
|
2021-11-30 19:41:34 +00:00
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
// setup player on first page load only:
|
|
|
|
useEffect(() => {
|
2021-11-25 18:02:37 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
const intervalID = setInterval(() => {
|
2021-12-11 16:25:43 +00:00
|
|
|
const currTime = audio.currentTime;
|
|
|
|
if (currTime == positionRef.current.currentTime) {
|
2021-11-25 18:02:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const duration = mediaSet.audioFrames / mediaSet.audioSampleRate;
|
2021-12-11 16:25:43 +00:00
|
|
|
const percent = (currTime / duration) * 100;
|
|
|
|
|
|
|
|
// check if the end of selection has been passed, and pause if so:
|
|
|
|
if (
|
|
|
|
currentTimeToFrame(position.currentTime) < selection.end &&
|
|
|
|
currentTimeToFrame(currTime) >= selection.end
|
|
|
|
) {
|
2022-01-14 11:54:54 +00:00
|
|
|
pause();
|
2021-12-11 16:25:43 +00:00
|
|
|
}
|
2021-11-25 18:02:37 +00:00
|
|
|
|
2021-12-11 16:25:43 +00:00
|
|
|
// update the current position
|
|
|
|
setPosition({ currentTime: audio.currentTime, percent: percent });
|
2021-11-30 19:41:34 +00:00
|
|
|
}, updatePlayerPositionIntevalMillis);
|
|
|
|
|
|
|
|
return () => clearInterval(intervalID);
|
2021-12-11 16:25:43 +00:00
|
|
|
}, [mediaSet, selection]);
|
|
|
|
|
|
|
|
// bind to keypress handler.
|
|
|
|
// selection is a dependency of the handleKeyPress handler, and must be
|
|
|
|
// included here.
|
|
|
|
useEffect(() => {
|
|
|
|
document.addEventListener('keypress', handleKeyPress);
|
|
|
|
return () => document.removeEventListener('keypress', handleKeyPress);
|
2022-01-14 11:54:54 +00:00
|
|
|
}, [playState]);
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2021-11-29 17:44:31 +00:00
|
|
|
// load audio when MediaSet is loaded:
|
|
|
|
useEffect(() => {
|
|
|
|
(async function () {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('fetching audio...');
|
|
|
|
const service = new MediaSetServiceClientImpl(newRPC());
|
2021-12-17 16:30:53 +00:00
|
|
|
const audioProgressStream = service.GetPeaks({
|
2021-11-29 17:44:31 +00:00
|
|
|
id: mediaSet.id,
|
|
|
|
numBins: CanvasLogicalWidth,
|
|
|
|
});
|
|
|
|
const peaks = audioProgressStream.pipe(map((progress) => progress.peaks));
|
|
|
|
setOverviewPeaks(peaks);
|
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
const pipe = audioProgressStream.pipe(
|
2021-12-17 16:30:53 +00:00
|
|
|
first((progress: GetPeaksProgress) => progress.url != '')
|
2021-11-30 19:41:34 +00:00
|
|
|
);
|
|
|
|
const progressWithURL = await firstValueFrom(pipe);
|
2021-11-29 17:44:31 +00:00
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
audio.src = progressWithURL.url;
|
2021-11-29 17:44:31 +00:00
|
|
|
audio.muted = false;
|
|
|
|
audio.volume = 1;
|
2021-11-30 19:41:34 +00:00
|
|
|
console.log('set audio src', progressWithURL.url);
|
2021-11-29 17:44:31 +00:00
|
|
|
})();
|
|
|
|
}, [mediaSet]);
|
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
// load video when MediaSet is loaded:
|
|
|
|
useEffect(() => {
|
2021-11-20 18:29:34 +00:00
|
|
|
(async function () {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-02 16:20:47 +00:00
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
console.log('fetching video...');
|
|
|
|
const service = new MediaSetServiceClientImpl(newRPC());
|
2021-11-20 18:29:34 +00:00
|
|
|
const videoProgressStream = service.GetVideo({ id: mediaSet.id });
|
2021-11-30 19:41:34 +00:00
|
|
|
const pipe = videoProgressStream.pipe(
|
|
|
|
first((progress: GetVideoProgress) => progress.url != '')
|
|
|
|
);
|
|
|
|
const progressWithURL = await firstValueFrom(pipe);
|
2021-11-20 18:29:34 +00:00
|
|
|
|
2021-11-30 19:41:34 +00:00
|
|
|
video.src = progressWithURL.url;
|
|
|
|
console.log('set video src', progressWithURL.url);
|
2021-11-20 18:29:34 +00:00
|
|
|
})();
|
2021-10-08 14:38:35 +00:00
|
|
|
}, [mediaSet]);
|
|
|
|
|
|
|
|
// set viewport when MediaSet is loaded:
|
|
|
|
useEffect(() => {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-17 17:53:27 +00:00
|
|
|
const numFrames = Math.min(
|
2021-12-06 22:52:24 +00:00
|
|
|
Math.round(mediaSet.audioFrames / CanvasLogicalWidth) *
|
|
|
|
initialViewportCanvasPixels,
|
2021-11-17 17:53:27 +00:00
|
|
|
mediaSet.audioFrames
|
|
|
|
);
|
|
|
|
|
|
|
|
setViewport({ start: 0, end: numFrames });
|
2021-10-08 14:38:35 +00:00
|
|
|
}, [mediaSet]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
console.debug('viewport updated', viewport);
|
|
|
|
}, [viewport]);
|
|
|
|
|
|
|
|
// handlers
|
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleKeyPress = (evt: KeyboardEvent) => {
|
|
|
|
if (evt.code != 'Space') {
|
|
|
|
return;
|
|
|
|
}
|
2021-11-30 19:41:34 +00:00
|
|
|
|
2022-01-14 11:54:54 +00:00
|
|
|
handleTogglePlay();
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2021-12-11 16:25:43 +00:00
|
|
|
|
|
|
|
// handler called when the selection in the overview (zoom setting) is changed.
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleOverviewSelectionChange = (newViewport: Frames) => {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
console.log('set new viewport', newViewport);
|
|
|
|
setViewport({ ...newViewport });
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
if (!audio.paused) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-11 16:25:43 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
setPositionFromFrame(newViewport.start);
|
|
|
|
};
|
2021-12-11 16:25:43 +00:00
|
|
|
|
|
|
|
// handler called when the selection in the main waveform view is changed.
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleWaveformSelectionChange = (newSelection: Frames) => {
|
|
|
|
setSelection(newSelection);
|
2021-12-11 16:25:43 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
2021-12-11 16:25:43 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
// move playback position to start of selection
|
|
|
|
const ratio = newSelection.start / mediaSet.audioFrames;
|
|
|
|
const currentTime =
|
|
|
|
(mediaSet.audioFrames / mediaSet.audioSampleRate) * ratio;
|
|
|
|
audio.currentTime = currentTime;
|
|
|
|
video.currentTime = currentTime;
|
|
|
|
};
|
2021-10-08 14:38:35 +00:00
|
|
|
|
2022-01-14 11:54:54 +00:00
|
|
|
const handleTogglePlay = () => {
|
|
|
|
if (playState == PlayState.Paused) {
|
|
|
|
play();
|
|
|
|
} else {
|
|
|
|
pause();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const play = () => {
|
2021-12-04 04:34:17 +00:00
|
|
|
audio.play();
|
|
|
|
video.play();
|
2022-01-14 11:54:54 +00:00
|
|
|
|
|
|
|
setPlayState(PlayState.Playing);
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2021-12-04 04:34:17 +00:00
|
|
|
|
2022-01-14 11:54:54 +00:00
|
|
|
const pause = () => {
|
2021-12-04 04:34:17 +00:00
|
|
|
video.pause();
|
|
|
|
audio.pause();
|
2021-12-11 16:25:43 +00:00
|
|
|
|
|
|
|
if (selection.start != selection.end) {
|
|
|
|
setPositionFromFrame(selection.start);
|
|
|
|
}
|
2022-01-14 11:54:54 +00:00
|
|
|
|
|
|
|
setPlayState(PlayState.Paused);
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2021-12-11 16:25:43 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleClip = () => {
|
2022-01-10 20:35:21 +00:00
|
|
|
if (!window.showSaveFilePicker) {
|
|
|
|
downloadClipHTTP();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadClipFileSystemAccessAPI();
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2022-01-10 20:35:21 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const downloadClipHTTP = () => {
|
2021-12-29 15:38:25 +00:00
|
|
|
(async function () {
|
2022-01-10 20:35:21 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
console.debug('clip http', selection);
|
|
|
|
|
|
|
|
const form = document.createElement('form');
|
|
|
|
form.method = 'POST';
|
|
|
|
form.action = `${apiURL}/api/media_sets/${mediaSet.id}/clip`;
|
|
|
|
const startFrameInput = document.createElement('input');
|
|
|
|
startFrameInput.type = 'hidden';
|
|
|
|
startFrameInput.name = 'start_frame';
|
|
|
|
startFrameInput.value = String(selection.start);
|
|
|
|
form.appendChild(startFrameInput);
|
|
|
|
const endFrameInput = document.createElement('input');
|
|
|
|
endFrameInput.type = 'hidden';
|
|
|
|
endFrameInput.name = 'end_frame';
|
|
|
|
endFrameInput.value = String(selection.end);
|
|
|
|
form.appendChild(endFrameInput);
|
|
|
|
const formatInput = document.createElement('input');
|
|
|
|
formatInput.type = 'hidden';
|
|
|
|
formatInput.name = 'format';
|
|
|
|
formatInput.value = 'mp3';
|
|
|
|
form.appendChild(formatInput);
|
|
|
|
document.body.appendChild(form);
|
|
|
|
form.submit();
|
|
|
|
})();
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2021-12-29 15:38:25 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const downloadClipFileSystemAccessAPI = () => {
|
2022-01-10 20:35:21 +00:00
|
|
|
(async function () {
|
2021-12-29 15:38:25 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-10 20:35:21 +00:00
|
|
|
console.debug('clip grpc', selection);
|
2021-12-29 15:38:25 +00:00
|
|
|
const h = await window.showSaveFilePicker({ suggestedName: 'clip.mp3' });
|
|
|
|
const fileStream = await h.createWritable();
|
|
|
|
|
|
|
|
const rpc = newRPC();
|
|
|
|
const service = new MediaSetServiceClientImpl(rpc);
|
|
|
|
const stream = service.GetAudioSegment({
|
|
|
|
id: mediaSet.id,
|
|
|
|
format: AudioFormat.MP3,
|
|
|
|
startFrame: selection.start,
|
|
|
|
endFrame: selection.end,
|
|
|
|
});
|
|
|
|
|
|
|
|
await stream.forEach((p) => fileStream.write(p.audioData));
|
|
|
|
console.debug('finished writing stream');
|
|
|
|
|
|
|
|
await fileStream.close();
|
|
|
|
console.debug('closed stream');
|
|
|
|
})();
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2021-12-29 15:38:25 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleZoomIn = () => {
|
2022-01-07 18:51:29 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-16 07:58:07 +00:00
|
|
|
|
|
|
|
const newViewport = zoomViewportIn(
|
|
|
|
viewport,
|
|
|
|
mediaSet.audioFrames,
|
|
|
|
selection,
|
|
|
|
currentTimeToFrame(positionRef.current.currentTime),
|
|
|
|
zoomFactor
|
|
|
|
);
|
|
|
|
|
|
|
|
setViewport(newViewport);
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2022-01-07 18:51:29 +00:00
|
|
|
|
2022-01-14 11:24:59 +00:00
|
|
|
const handleZoomOut = () => {
|
2022-01-07 18:51:29 +00:00
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
2022-01-16 07:58:07 +00:00
|
|
|
|
|
|
|
const newViewport = zoomViewportOut(
|
|
|
|
viewport,
|
|
|
|
mediaSet.audioFrames,
|
|
|
|
selection,
|
|
|
|
currentTimeToFrame(positionRef.current.currentTime),
|
|
|
|
zoomFactor
|
|
|
|
);
|
|
|
|
|
|
|
|
setViewport(newViewport);
|
2022-01-14 11:24:59 +00:00
|
|
|
};
|
2022-01-07 18:51:29 +00:00
|
|
|
|
2021-12-11 16:25:43 +00:00
|
|
|
const setPositionFromFrame = useCallback(
|
|
|
|
(frame: number) => {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const ratio = frame / mediaSet.audioFrames;
|
|
|
|
const currentTime =
|
|
|
|
(mediaSet.audioFrames / mediaSet.audioSampleRate) * ratio;
|
|
|
|
audio.currentTime = currentTime;
|
|
|
|
video.currentTime = currentTime;
|
|
|
|
},
|
2022-01-14 11:24:59 +00:00
|
|
|
[mediaSet]
|
2021-12-11 16:25:43 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// helpers
|
|
|
|
|
|
|
|
const currentTimeToFrame = useCallback(
|
|
|
|
(currentTime: number): number => {
|
|
|
|
if (mediaSet == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const dur = mediaSet.audioFrames / mediaSet.audioSampleRate;
|
|
|
|
const ratio = currentTime / dur;
|
|
|
|
return Math.round(mediaSet.audioFrames * ratio);
|
|
|
|
},
|
|
|
|
[mediaSet]
|
|
|
|
);
|
2021-12-04 04:34:17 +00:00
|
|
|
|
2021-10-08 14:38:35 +00:00
|
|
|
// render component
|
|
|
|
|
2021-11-02 16:20:47 +00:00
|
|
|
const offsetPixels = Math.floor(thumbnailWidth / 2);
|
2022-01-14 11:54:54 +00:00
|
|
|
const marginClass = 'mx-[88px]'; // offsetPixels
|
2021-10-08 14:38:35 +00:00
|
|
|
|
|
|
|
if (mediaSet == null) {
|
|
|
|
// TODO: improve
|
|
|
|
return <></>;
|
|
|
|
}
|
|
|
|
|
2021-09-06 10:17:50 +00:00
|
|
|
return (
|
2021-10-08 14:38:35 +00:00
|
|
|
<>
|
2022-01-14 11:54:54 +00:00
|
|
|
<div className="App bg-gray-800 h-screen flex flex-col">
|
|
|
|
<header className="bg-green-900 h-16 grow-0 flex items-center mb-12 px-[88px]">
|
|
|
|
<h1 className="text-3xl font-bold">Clipper</h1>
|
|
|
|
</header>
|
|
|
|
<div className="flex flex-col grow-1 bg-gray-800 w-full h-full mx-auto">
|
|
|
|
<div className={`flex flex-col grow ${marginClass}`}>
|
|
|
|
<div className="flex grow-0 h-8 pt-4 pb-2 items-center space-x-2 text-white">
|
|
|
|
<span className="text-gray-300">{mediaSet.author}</span>
|
|
|
|
<span>/</span>
|
|
|
|
<span>{mediaSet.title}</span>
|
|
|
|
<a
|
|
|
|
href={`https://www.youtube.com/watch?v=${mediaSet.youtubeId}`}
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
title="Open in YouTube"
|
|
|
|
>
|
|
|
|
<ExternalLinkIcon className="h-6 w-6 text-gray-500 hover:text-gray-200" />
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<ControlBar
|
|
|
|
playState={playState}
|
|
|
|
onTogglePlay={handleTogglePlay}
|
|
|
|
onClip={handleClip}
|
|
|
|
onZoomIn={handleZoomIn}
|
|
|
|
onZoomOut={handleZoomOut}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Overview
|
|
|
|
peaks={overviewPeaks}
|
|
|
|
mediaSet={mediaSet}
|
|
|
|
viewport={viewport}
|
|
|
|
position={position}
|
|
|
|
onSelectionChange={handleOverviewSelectionChange}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Waveform
|
|
|
|
mediaSet={mediaSet}
|
|
|
|
position={position}
|
|
|
|
viewport={viewport}
|
|
|
|
onSelectionChange={handleWaveformSelectionChange}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-10-08 14:38:35 +00:00
|
|
|
|
|
|
|
<SeekBar
|
|
|
|
position={video.currentTime}
|
2021-11-02 16:20:47 +00:00
|
|
|
duration={mediaSet.audioFrames / mediaSet.audioSampleRate}
|
2021-10-08 14:38:35 +00:00
|
|
|
offsetPixels={offsetPixels}
|
|
|
|
onPositionChanged={(position: number) => {
|
|
|
|
video.currentTime = position;
|
2021-11-29 17:44:31 +00:00
|
|
|
audio.currentTime = position;
|
2021-10-08 14:38:35 +00:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<VideoPreview
|
2021-11-21 19:43:40 +00:00
|
|
|
mediaSet={mediaSet}
|
2021-10-08 14:38:35 +00:00
|
|
|
video={video}
|
|
|
|
position={position}
|
2021-11-02 16:20:47 +00:00
|
|
|
duration={millisFromDuration(mediaSet.videoDuration)}
|
2021-10-08 14:38:35 +00:00
|
|
|
/>
|
|
|
|
</div>
|
2022-01-14 11:54:54 +00:00
|
|
|
<ul className="hidden">
|
2021-12-11 16:25:30 +00:00
|
|
|
<li>Frames: {mediaSet.audioFrames}</li>
|
|
|
|
<li>
|
|
|
|
Viewport (frames): {viewport.start} to {viewport.end}
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Selection (frames): {selection.start} to {selection.end}
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
Position (frames):{' '}
|
|
|
|
{Math.round(mediaSet.audioFrames * (position.percent / 100))}
|
|
|
|
</li>
|
|
|
|
<li>Position (seconds): {position.currentTime}</li>
|
|
|
|
<li></li>
|
|
|
|
</ul>
|
2021-10-08 14:38:35 +00:00
|
|
|
</div>
|
|
|
|
</>
|
2021-09-06 10:17:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default App;
|
2021-11-02 16:20:47 +00:00
|
|
|
|
2021-11-04 06:13:00 +00:00
|
|
|
export function newRPC(): GrpcWebImpl {
|
2021-11-27 13:26:14 +00:00
|
|
|
return new GrpcWebImpl(apiURL, {});
|
2021-11-04 06:13:00 +00:00
|
|
|
}
|