|
|
@@ -20,29 +20,32 @@
|
|
|
|
|
|
#define WAVPLAYER_FOLDER "/ext/wav_player"
|
|
|
|
|
|
-static bool open_wav_stream(Stream* stream) {
|
|
|
+static bool open_wav_stream(WavPlayerApp* app) {
|
|
|
DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS);
|
|
|
bool result = false;
|
|
|
- FuriString* path;
|
|
|
- path = furi_string_alloc();
|
|
|
- furi_string_set(path, WAVPLAYER_FOLDER);
|
|
|
-
|
|
|
- DialogsFileBrowserOptions browser_options;
|
|
|
- dialog_file_browser_set_basic_options(&browser_options, ".wav", &I_music_10px);
|
|
|
- browser_options.base_path = WAVPLAYER_FOLDER;
|
|
|
- browser_options.hide_ext = false;
|
|
|
-
|
|
|
- bool ret = dialog_file_browser_show(dialogs, path, path, &browser_options);
|
|
|
-
|
|
|
- furi_record_close(RECORD_DIALOGS);
|
|
|
- if(ret) {
|
|
|
- if(!file_stream_open(stream, furi_string_get_cstr(path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
- FURI_LOG_E(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(path));
|
|
|
- } else {
|
|
|
- result = true;
|
|
|
- }
|
|
|
+
|
|
|
+ if(furi_string_empty(app->path)) {
|
|
|
+ furi_string_set(app->path, WAVPLAYER_FOLDER);
|
|
|
+
|
|
|
+ DialogsFileBrowserOptions browser_options;
|
|
|
+ dialog_file_browser_set_basic_options(&browser_options, ".wav", &I_music_10px);
|
|
|
+ browser_options.base_path = WAVPLAYER_FOLDER;
|
|
|
+ browser_options.hide_ext = false;
|
|
|
+
|
|
|
+ bool ret = dialog_file_browser_show(dialogs, app->path, app->path, &browser_options);
|
|
|
+
|
|
|
+ furi_record_close(RECORD_DIALOGS);
|
|
|
+
|
|
|
+ if(!ret) return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!file_stream_open(
|
|
|
+ app->stream, furi_string_get_cstr(app->path), FSAM_READ, FSOM_OPEN_EXISTING)) {
|
|
|
+ FURI_LOG_E(TAG, "Cannot open file \"%s\"", furi_string_get_cstr(app->path));
|
|
|
+ } else {
|
|
|
+ result = true;
|
|
|
}
|
|
|
- furi_string_free(path);
|
|
|
+
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -99,6 +102,8 @@ static WavPlayerApp* app_alloc() {
|
|
|
app->view_dispatcher = view_dispatcher_alloc();
|
|
|
app->view = wav_player_view_alloc();
|
|
|
|
|
|
+ app->path = furi_string_alloc();
|
|
|
+
|
|
|
view_dispatcher_add_view(app->view_dispatcher, 0, wav_player_view_get_view(app->view));
|
|
|
view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen);
|
|
|
view_dispatcher_switch_to_view(app->view_dispatcher, 0);
|
|
|
@@ -122,6 +127,8 @@ static void app_free(WavPlayerApp* app) {
|
|
|
stream_free(app->stream);
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
+ furi_string_free(app->path);
|
|
|
+
|
|
|
notification_message(app->notification, &sequence_display_backlight_enforce_auto);
|
|
|
furi_record_close(RECORD_NOTIFICATION);
|
|
|
free(app);
|
|
|
@@ -344,7 +351,8 @@ static void ctrl_callback(WavPlayerCtrl ctrl, void* ctx) {
|
|
|
}
|
|
|
|
|
|
static void app_run(WavPlayerApp* app) {
|
|
|
- if(!open_wav_stream(app->stream)) return;
|
|
|
+ if(!open_wav_stream(app)) return;
|
|
|
+
|
|
|
if(!wav_parser_parse(app->parser, app->stream, app)) return;
|
|
|
|
|
|
wav_player_view_set_volume(app->view, app->volume);
|
|
|
@@ -449,7 +457,8 @@ static void app_run(WavPlayerApp* app) {
|
|
|
}
|
|
|
|
|
|
int32_t wav_player_app(void* p) {
|
|
|
- UNUSED(p);
|
|
|
+ const char* args = p;
|
|
|
+
|
|
|
WavPlayerApp* app = app_alloc();
|
|
|
|
|
|
Storage* storage = furi_record_open(RECORD_STORAGE);
|
|
|
@@ -458,6 +467,10 @@ int32_t wav_player_app(void* p) {
|
|
|
}
|
|
|
furi_record_close(RECORD_STORAGE);
|
|
|
|
|
|
+ if(args && strlen(args)) {
|
|
|
+ furi_string_set(app->path, args);
|
|
|
+ }
|
|
|
+
|
|
|
app_run(app);
|
|
|
app_free(app);
|
|
|
return 0;
|