Help - Search - Members - Calendar
Full Version: Loading/saving playlists
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
mixcherry
Could someone post a simple example how to load and save playlists (including uGetOpenFileNameMulti with properly constructed extension mask). I'm trying to rewrite part of Playlist Switcher code from 0.8.3 SDK examples (without success sad.gif).

[EDIT]
  1. Sorry, I've just done it.

    But I'm not sure if I've done it right wink.gif Here's the code I use:
    CODE
    uGetOpenFileNameMultiResult * result;
    result = uGetOpenFileNameMulti(wnd, filter, 0, "fpl", "Load playlist...", "");

    if (result) {
        unsigned n, m=result->GetCount();
        for (n=0; n<m; n++) {
            const char * fn = result->GetFileName(n);
            abort_callback_impl abort;
            playlist_loader_callback_impl playlist_data(abort);
            try {
                playlist_loader::g_load_playlist(fn, playlist_data);
                pfc::string8 tempname = pfc::string_filename(fn);
                static_api_ptr_t< playlist_manager > pm;
                t_size playlist = pm->create_playlist(tempname, infinite, infinite);
                bit_array_bittable mask(playlist_data.get_count());
                pm->playlist_add_items(playlist, playlist_data.get_data(), mask);
            } catch (const exception_io &) { /* o_O */ }
            catch (const exception_service_not_found &) { /* o_0 */ };
        }
        delete result;
    }

    Should I do something with catched "exception_io", or should I catch more exceptions? What exactly is bit_array &p_selection for? (in playlist_add_items()).


  2. Now I'm trying to save playlist:
    CODE
    try {
        static_api_ptr_t< playlist_manager > pm;
        metadb_handle_list temp;
        pm->playlist_get_all_items(current_playlist, temp);
        menu_helpers::run_command_context(standard_commands::guid_context_save_playlist, standard_commands::guid_context_save_playlist, temp);
    } catch (const exception_service_not_found &) { /* o_0 */ }

    It doesn't work... Probably (=certainly) because I don't know what should be the 2nd parameter (GUID &p_subcommand) when I execute run_command_context().
[/EDIT]
foosion
QUOTE(mixcherry @ May 28 2006, 12:02) *
Should I do something with catched "exception_io", or should I catch more exceptions?
Catching exception_aborted never hurts. wink.gif It is also one of the exceptions that almost always require special handling, as it is not the result of an error. For the rest - std::exception or whatever subset you choose - , you should display them to the user in some way; either through the popup_message service where appropriate or at least on the console.

QUOTE(mixcherry @ May 28 2006, 12:02) *
What exactly is bit_array &p_selection for? (in playlist_add_items()).
It is used to set the selection state of the added items. For example, you could pass in bit_array_true() - as a temporary object - to have all the newly added items selected. If you want to have only those selected, you have to clear the selection in that playlist before (playlist_manager::playlist_clear_selection).

QUOTE(mixcherry @ May 28 2006, 12:02) *
It doesn't work... Probably (=certainly) because I don't know what should be the 2nd parameter (GUID &p_subcommand) when I execute run_command_context().
The p_subcommand parameter is used in cases where a command really is a submenu instead of a single command. In the case of the standard commands it is always a null GUID. You can also use standard_commands::context_save_playlist() to run this particular command.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.