Skip to content

Commit

Permalink
feat(linux): setBalance - doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
novikov-studio committed Aug 13, 2022
1 parent 3d03e9c commit cc75572
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/audioplayers_linux/linux/audio_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ AudioPlayer::AudioPlayer(std::string playerId, FlMethodChannel *channel)
return;
}

// Add audiopanorama plugin
panorama = gst_element_factory_make("audiopanorama", "audiopanorama");
gst_bin_add(GST_BIN(playbin), panorama);

// Setup source options
g_signal_connect(playbin, "source-setup",
G_CALLBACK(AudioPlayer::SourceSetup), &source);
Expand Down Expand Up @@ -190,6 +194,16 @@ void AudioPlayer::OnPlaybackEnded() {
}
}

void AudioPlayer::SetBalance(float balance) {
if (balance > 1.0f) {
balance = 1.0f;
} else if (balance < 0.0f) {
balance = 0.0f;
}
g_object_set(G_OBJECT(panorama), "method", 1, NULL);
g_object_set(G_OBJECT(panorama), "panorama", balance, NULL);
}

void AudioPlayer::SetLooping(bool isLooping) {
_isLooping = isLooping;
}
Expand Down Expand Up @@ -331,6 +345,7 @@ void AudioPlayer::Dispose() {
}
gst_object_unref(bus);
gst_object_unref(source);
gst_object_unref(panorama);

gst_element_set_state(playbin, GST_STATE_NULL);
gst_object_unref(playbin);
Expand Down
3 changes: 3 additions & 0 deletions packages/audioplayers_linux/linux/audio_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class AudioPlayer {

void Dispose();

void SetBalance(float balance);

void SetLooping(bool isLooping);

void SetVolume(double volume);
Expand All @@ -53,6 +55,7 @@ class AudioPlayer {
// Gst members
GstElement *playbin;
GstElement *source;
GstElement *panorama;
GstBus *bus;

bool _isInitialized = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,14 @@ static void audioplayers_linux_plugin_handle_method_call(
// TODO check support for low latency mode:
// https://gstreamer.freedesktop.org/documentation/additional/design/latency.html?gi-language=c
result = 1;
} else {
} else if (strcmp(method, "setBalance") == 0) {
auto flBalance = fl_value_lookup_string(args, "balance");
double balance =
flBalance == nullptr ? 0.0f : fl_value_get_float(flBalance);
player->SetBalance(balance);
result = 1;
}
else {
response = FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
fl_method_call_respond(method_call, response, nullptr);
return;
Expand Down

0 comments on commit cc75572

Please sign in to comment.