-
-
Notifications
You must be signed in to change notification settings - Fork 51
Feat/long file playback #993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mdydek
wants to merge
26
commits into
main
Choose a base branch
from
feat/long-file-playback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
56f0f58
feat: ai slop long files playback node
maciejmakowski2003 429310a
feat: file playback
mdydek feaecf6
feat: working ffmpeg files playback
mdydek a54bbe3
feat: alpha integration with audio tag
mdydek 0e1c08a
feat: basic integration with audio tag
mdydek 1935fba
fix: tests
mdydek 9b0e748
fix: testsV2
mdydek df70d91
feat: loop controls state
mdydek 25e4a63
feat: working beta
mdydek 979b34d
feat: offload seek to a separate thread
mdydek 923537a
chore: removed AudioContent.tsx
mdydek d8534b8
chore: removed .swift file
mdydek 35bbbac
chore: original .swift file
mdydek 045450a
chore: renamed example
mdydek 62bb5ad
refactor: cleanup
mdydek 485eca6
refactor: changed spsc strategies
mdydek 2440c8f
refactor: improvements on verbosity
mdydek 13f5a37
feat: static icons try
mdydek 586cbb9
feat: added ffmpeg flag to options
mdydek a626a1e
feat: remove unnecessary icon dependency
mdydek e618442
refactor: common decoders
mdydek 2d0e82d
Merge branch 'main' into feat/long-file-playback
mdydek 907c558
feat: node as audio scheduled source node
mdydek 79aa893
refactor: comments
mdydek 822a342
refactor: adjusted api approach
mdydek 71b95ea
refactor: react cleanup
mdydek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import React, { useRef } from 'react'; | ||
| import { Button, View } from 'react-native'; | ||
| import { Audio, AudioTagHandle } from 'react-native-audio-api/development/react'; | ||
|
|
||
| import { Container } from '../../components'; | ||
|
|
||
| // const DEMO_AUDIO_URL = 'https://filesamples.com/samples/audio/m4a/sample4.m4a'; | ||
| const DEMO_AUDIO_URL = 'https://filesamples.com/samples/audio/mp3/sample4.mp3'; | ||
|
|
||
| const AudioTag: React.FC = () => { | ||
| const audioRef = useRef<AudioTagHandle>(null); | ||
|
|
||
| // const handlePlay = () => { | ||
| // audioRef.current?.play(); | ||
| // }; | ||
|
|
||
| // const handlePause = () => { | ||
| // audioRef.current?.pause(); | ||
| // }; | ||
|
|
||
| // const handleSeekToTime = (time: number) => { | ||
| // console.log('handleSeekToTime', time); | ||
| // audioRef.current?.seekToTime(time); | ||
| // }; | ||
|
|
||
| // const handleSetVolume = (volume: number) => { | ||
| // audioRef.current?.setVolume(volume); | ||
| // }; | ||
|
|
||
| // const handleSetMuted = (muted: boolean) => { | ||
| // audioRef.current?.setMuted(muted); | ||
| // }; | ||
|
|
||
| return ( | ||
| <Container disablePadding> | ||
| <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | ||
| <View style={{ width: '90%' }}> | ||
| <Audio source={DEMO_AUDIO_URL} ref={audioRef} controls | ||
| onLoadStart={() => console.log('onLoadStart')} | ||
| onLoad={() => console.log('onLoad')} | ||
| onError={(error) => console.log('onError', error)} | ||
| onPositionChange={(seconds) => | ||
| console.log('onPositionChange', seconds) | ||
| } | ||
| onEnded={() => console.log('onEnded')} | ||
| onPlay={() => console.log('onPlay')} | ||
| onPause={() => console.log('onPause')} | ||
| onVolumeChange={(volume) => console.log('onVolumeChange', volume)} | ||
| /> | ||
| </View> | ||
| </View> | ||
| </Container> | ||
| ); | ||
| }; | ||
|
|
||
| export default AudioTag; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './AudioTag'; |
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
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
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
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
129 changes: 129 additions & 0 deletions
129
...ative-audio-api/common/cpp/audioapi/HostObjects/sources/AudioFileSourceNodeHostObject.cpp
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| #include <audioapi/HostObjects/sources/AudioFileSourceNodeHostObject.h> | ||
|
|
||
| #include <audioapi/core/BaseAudioContext.h> | ||
| #include <audioapi/core/sources/AudioFileSourceNode.h> | ||
| #include <audioapi/types/NodeOptions.h> | ||
| #include <memory> | ||
| #include <utility> | ||
| #include "audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h" | ||
|
|
||
| namespace audioapi { | ||
|
|
||
| AudioFileSourceNodeHostObject::AudioFileSourceNodeHostObject( | ||
| const std::shared_ptr<BaseAudioContext> &context, | ||
| const AudioFileSourceOptions &options) | ||
| : AudioScheduledSourceNodeHostObject(context->createFileSource(options), options), | ||
| loop_(options.loop), | ||
| volume_(options.volume), | ||
| duration_(std::static_pointer_cast<AudioFileSourceNode>(node_)->getDuration()) { | ||
| addGetters( | ||
| JSI_EXPORT_PROPERTY_GETTER(AudioFileSourceNodeHostObject, volume), | ||
| JSI_EXPORT_PROPERTY_GETTER(AudioFileSourceNodeHostObject, loop), | ||
| JSI_EXPORT_PROPERTY_GETTER(AudioFileSourceNodeHostObject, currentTime), | ||
| JSI_EXPORT_PROPERTY_GETTER(AudioFileSourceNodeHostObject, duration)); | ||
| addSetters( | ||
| JSI_EXPORT_PROPERTY_SETTER(AudioFileSourceNodeHostObject, onPositionChanged), | ||
| JSI_EXPORT_PROPERTY_SETTER(AudioFileSourceNodeHostObject, onEnded), | ||
| JSI_EXPORT_PROPERTY_SETTER(AudioFileSourceNodeHostObject, volume), | ||
| JSI_EXPORT_PROPERTY_SETTER(AudioFileSourceNodeHostObject, loop)); | ||
|
|
||
| addFunctions( | ||
| JSI_EXPORT_FUNCTION(AudioFileSourceNodeHostObject, pause), | ||
| JSI_EXPORT_FUNCTION(AudioFileSourceNodeHostObject, start), | ||
| JSI_EXPORT_FUNCTION(AudioFileSourceNodeHostObject, seekToTime)); | ||
| } | ||
|
|
||
| AudioFileSourceNodeHostObject::~AudioFileSourceNodeHostObject() { | ||
| setOnPositionChangedCallbackId(0); | ||
| setOnEndedCallbackId(0); | ||
| } | ||
|
|
||
| JSI_PROPERTY_GETTER_IMPL(AudioFileSourceNodeHostObject, volume) { | ||
| return {volume_}; | ||
| } | ||
|
|
||
| JSI_PROPERTY_SETTER_IMPL(AudioFileSourceNodeHostObject, volume) { | ||
| auto node = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
| volume_ = static_cast<float>(value.getNumber()); | ||
| auto event = [node, volume = this->volume_](BaseAudioContext &ctx) { | ||
| node->setVolume(volume); | ||
| }; | ||
| node->scheduleAudioEvent(std::move(event)); | ||
| } | ||
|
|
||
| JSI_PROPERTY_GETTER_IMPL(AudioFileSourceNodeHostObject, loop) { | ||
| return {loop_}; | ||
| } | ||
|
|
||
| JSI_PROPERTY_SETTER_IMPL(AudioFileSourceNodeHostObject, loop) { | ||
| auto node = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
| loop_ = value.getBool(); | ||
| auto event = [node, loop = this->loop_](BaseAudioContext &ctx) { | ||
| node->setLoop(loop); | ||
| }; | ||
| node->scheduleAudioEvent(std::move(event)); | ||
| } | ||
|
|
||
| JSI_PROPERTY_GETTER_IMPL(AudioFileSourceNodeHostObject, currentTime) { | ||
| auto node = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
| return {node->getCurrentTime()}; | ||
| } | ||
|
|
||
| JSI_PROPERTY_GETTER_IMPL(AudioFileSourceNodeHostObject, duration) { | ||
| return {duration_}; | ||
| } | ||
|
|
||
| JSI_HOST_FUNCTION_IMPL(AudioFileSourceNodeHostObject, pause) { | ||
| auto audioFileSourceNode = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
| auto event = [audioFileSourceNode](BaseAudioContext &ctx) { | ||
| audioFileSourceNode->pause(); | ||
| }; | ||
| audioFileSourceNode->scheduleAudioEvent(std::move(event)); | ||
| return jsi::Value::undefined(); | ||
| } | ||
|
|
||
| JSI_HOST_FUNCTION_IMPL(AudioFileSourceNodeHostObject, seekToTime) { | ||
| auto audioFileSourceNode = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
| if (count < 1 || !args[0].isNumber()) { | ||
| return jsi::Value::undefined(); | ||
| } | ||
| const double t = args[0].getNumber(); | ||
|
|
||
| auto event = [audioFileSourceNode, t](BaseAudioContext &) { | ||
| audioFileSourceNode->seekToTime(t); | ||
| }; | ||
| audioFileSourceNode->scheduleAudioEvent(std::move(event)); | ||
|
|
||
| return jsi::Value::undefined(); | ||
| } | ||
|
|
||
| JSI_PROPERTY_SETTER_IMPL(AudioFileSourceNodeHostObject, onPositionChanged) { | ||
| auto callbackId = std::stoull(value.getString(runtime).utf8(runtime)); | ||
| setOnPositionChangedCallbackId(callbackId); | ||
| } | ||
|
|
||
| void AudioFileSourceNodeHostObject::setOnPositionChangedCallbackId(uint64_t callbackId) { | ||
| auto sourceNode = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
|
|
||
| auto event = [sourceNode, callbackId](BaseAudioContext &) { | ||
| sourceNode->setOnPositionChangedCallbackId(callbackId); | ||
| }; | ||
|
|
||
| sourceNode->unregisterOnPositionChangedCallback(onPositionChangedCallbackId_); | ||
| sourceNode->scheduleAudioEvent(std::move(event)); | ||
| onPositionChangedCallbackId_ = callbackId; | ||
| } | ||
poneciak57 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| void AudioFileSourceNodeHostObject::setOnEndedCallbackId(uint64_t callbackId) { | ||
| auto sourceNode = std::static_pointer_cast<AudioFileSourceNode>(node_); | ||
|
|
||
| auto event = [sourceNode, callbackId](BaseAudioContext &) { | ||
| sourceNode->setOnEndedCallbackId(callbackId); | ||
| }; | ||
|
|
||
| sourceNode->unregisterOnEndedCallback(onEndedCallbackId_); | ||
| sourceNode->scheduleAudioEvent(std::move(event)); | ||
| onEndedCallbackId_ = callbackId; | ||
| } | ||
poneciak57 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } // namespace audioapi | ||
45 changes: 45 additions & 0 deletions
45
...-native-audio-api/common/cpp/audioapi/HostObjects/sources/AudioFileSourceNodeHostObject.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| #pragma once | ||
|
|
||
| #include <audioapi/HostObjects/sources/AudioScheduledSourceNodeHostObject.h> | ||
| #include <memory> | ||
|
|
||
| namespace audioapi { | ||
| using namespace facebook; | ||
|
|
||
| struct AudioFileSourceOptions; | ||
| class BaseAudioContext; | ||
|
|
||
| class AudioFileSourceNodeHostObject : public AudioScheduledSourceNodeHostObject { | ||
| public: | ||
| explicit AudioFileSourceNodeHostObject( | ||
| const std::shared_ptr<BaseAudioContext> &context, | ||
| const AudioFileSourceOptions &options); | ||
|
|
||
| ~AudioFileSourceNodeHostObject() override; | ||
|
|
||
| JSI_PROPERTY_GETTER_DECL(volume); | ||
| JSI_PROPERTY_GETTER_DECL(loop); | ||
| JSI_PROPERTY_GETTER_DECL(currentTime); | ||
| JSI_PROPERTY_GETTER_DECL(duration); | ||
|
|
||
| JSI_PROPERTY_SETTER_DECL(volume); | ||
| JSI_PROPERTY_SETTER_DECL(loop); | ||
| JSI_PROPERTY_SETTER_DECL(onPositionChanged); | ||
|
|
||
| JSI_HOST_FUNCTION_DECL(pause); | ||
| JSI_HOST_FUNCTION_DECL(seekToStart); | ||
| JSI_HOST_FUNCTION_DECL(seekToTime); | ||
|
|
||
| private: | ||
| uint64_t onPositionChangedCallbackId_ = 0; | ||
| uint64_t onEndedCallbackId_ = 0; | ||
|
|
||
| void setOnPositionChangedCallbackId(uint64_t callbackId); | ||
| void setOnEndedCallbackId(uint64_t callbackId); | ||
|
|
||
| bool loop_; | ||
| double duration_; | ||
| float volume_; | ||
| }; | ||
|
|
||
| } // namespace audioapi |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.