Conversation
michalsek
requested changes
Mar 20, 2026
| private: | ||
| std::shared_ptr<AudioFileDecoderState> decoderState_; | ||
| std::atomic<float> volume_; | ||
| bool FFmpegNeeded_; |
Member
There was a problem hiding this comment.
nit
Suggested change
| bool FFmpegNeeded_; | |
| bool requiresFFmpeg_; |
Comment on lines
+29
to
+38
| export const AudioComponentContext = createContext<AudioComponentContextType>({ | ||
| play: () => {}, | ||
| pause: () => {}, | ||
| volume: 1, | ||
| setVolume: () => {}, | ||
| muted: false, | ||
| setMuted: () => {}, | ||
| isReady: false, | ||
| playbackState: 'idle', | ||
| }); |
Member
There was a problem hiding this comment.
would be great to extract it to separate file ie. audioTagContex.ts
Member
There was a problem hiding this comment.
and on second though we could go with
createContext<AudioComponentContextType | null>(null);plus a helper hook
function useAudioTagContext() {
const context = useContext(AudioComponentContext);
if (!context) {
throw new Error("useAudioTagContext used within a provider tag!");
}
return context; // always returns AudioComponentContextType
}| useState<AudioTagPlaybackState>('idle'); | ||
|
|
||
| const volumeStateRef = useRef(volumeState); | ||
| volumeStateRef.current = volumeState; |
| volumeStateRef.current = volumeState; | ||
|
|
||
| const mutedStateRef = useRef(mutedState); | ||
| mutedStateRef.current = mutedState; |
| mutedStateRef.current = mutedState; | ||
|
|
||
| const contextRef = useRef(context); | ||
| contextRef.current = context; |
Comment on lines
+120
to
+149
| useEffect(() => { | ||
| if (!context || !path) { | ||
| return; | ||
| } | ||
|
|
||
| const run = async () => { | ||
| if (path.startsWith('http')) { | ||
| const response = await fetch(path); | ||
| const arrayBuffer = await response.arrayBuffer(); | ||
| attachNode(context.context.createFileSource(arrayBuffer)); | ||
| } else { | ||
| attachNode(context.context.createFileSource(path)); | ||
| } | ||
| }; | ||
|
|
||
| setIsReady(false); | ||
| setPlaybackState('idle'); | ||
| run(); | ||
|
|
||
| return () => { | ||
| const prev = nodeRef.current; | ||
| if (prev) { | ||
| prev.onEnded = '0'; | ||
| } | ||
| prev?.disconnect(undefined); | ||
| nodeRef.current = null; | ||
| setIsReady(false); | ||
| setPlaybackState('idle'); | ||
| }; | ||
| }, [path, context, attachNode]); |
Member
There was a problem hiding this comment.
this means that each time we toggle play state whe fetch and load the file again
Member
There was a problem hiding this comment.
You can try using the vercels react best practices to cleanup a bit the component code :)
| preservesPitch: boolean; | ||
| volume: number; | ||
| children?: ReactNode; | ||
| context: BaseAudioContext | null; // null on web, since web do not use AudioContext for audio tag |
Member
There was a problem hiding this comment.
Suggested change
| context: BaseAudioContext | null; // null on web, since web do not use AudioContext for audio tag | |
| context?: BaseAudioContext; // optional on web, since web do not use AudioContext for audio tag |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #735
Introduced changes
Checklist