-
-
Notifications
You must be signed in to change notification settings - Fork 173
Sound support #120
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
Comments
Flutter doesn't have official audio support as of now. (ref) The most popular plugin for audio support seems to be For example, look at Some code to listen and decode this in a flutter-pi flutter-pi plugin would look like the following: // sadly, because of some stupid design decisions I made when starting this project, we sometimes need to rely
// on global state.
struct {
} my_audio_plugin;
int on_play(struct std_value *arg, FlutterPlatformMessageResponseHandle *responsehandle) {
struct std_value *temp;
int64_t player_id;
if (!STDVALUE_IS_MAP(*arg)) {
return platch_respond_illegal_arg_std(
responsehandle,
"Expected `arg` to be a map."
);
}
temp = stdmap_get_str(arg, "playerId");
if (((temp != NULL) && STDVALUE_IS_INT(*temp)) {
player_id = STDVALUE_AS_INT(*arg);
} else {
return platch_respond_illegal_arg_std(
responsehandle,
"Expected 'arg['playerId']` to be an integer."
);
}
// ...
return platch_respond_success_std(responsehandle, &STDINT64(1));
}
int on_method_call(char *channel, struct platch_obj *object, FlutterPlatformMessageResponseHandle *responsehandle) {
// we received a method call on "xyz.luan/audioplayers"
// check the name of the method.
// a struct platch_obj is basically a decoded platform message.
// See `platformchannel.h` for more documentation on that.
char *method_name = object->method;
if (strcmp(method_name, "play") == 0) {
return on_play(object->, responsehandle);
} else {
// respond with not implemented.
// this will trigger a `MissingPluginException` in the dart VM.
return platch_respond_not_implemented(responsehandle);
}
}
int my_audio_plugin_init(void) {
// register a callback to be invoked on the programs main thread when
// a platform message is received on channel "xyz.luan/audioplayers"
// and automatically decode it as a standard method codec method call.
// (== method channel)
plugin_registry_set_receiver("xyz.luan/audioplayers", kStandardMethodCall, on_method_call);
return 0;
}
int my_audio_plugin_deinit(void) {
plugin_registry_remove_receiver("xyz.luan/audioplayers");
return 0;
} You'll find some documentation in the header & source files. If you have any questions, feel free to ask. The platform channel and plugin registry APIs are (99% at least) thread-safe. You also don't need to reply to the method call synchronously. You can take your time, maybe pass the responsehandle to some worker thread, and let that worker thread respond to the platform message using As to the implementation of the actual audio playback: Ngl, gstreamer is kinda complicated and not that easy to work with, but it supports hardware decoding and, in contrast to VLC player for example, supports zero-copy and dmabufs. Dmabufs are good because they have integrated support in EGL. You can just import a dmabuf to an OpenGL texture without any memory copied. Generally, zero-copy is good to have on embedded devices like the Pi, since memory bandwidth is kinda scarce. |
@ardera awesome stuff!
does video and audio playback stable as of now? you still using gstreamer? have you pushed the branch? thanks |
@ardera |
audio player plugin merged a few weeks ago, you should be able to use the |
Hello @ardera , I've added |
When attempting to call
|
All this time there was incorrect code and I didn't notice as I used my own fork of flutter-pi |
From what I can tell, there is currently no support for playing sounds? Any advice as where would be a good starting point for making an implementation?
The text was updated successfully, but these errors were encountered: