Ticket #13845: 0004-Expose-the-current-track-as-a-scripting-object.patch

File 0004-Expose-the-current-track-as-a-scripting-object.patch, 1.7 KB (added by owenca, 6 years ago)
  • src/apps/mediaplayer/MainWin.cpp

    From fcc0c181248af443594e3ab643097abd92191ae1 Mon Sep 17 00:00:00 2001
    From: Owen <owenca@users.noreply.github.com>
    Date: Fri, 15 Dec 2017 06:23:10 +0000
    Subject: [PATCH 5/5] Expose the current track as a scripting object.
    
    ---
     src/apps/mediaplayer/MainWin.cpp | 20 +++++++++++++++++---
     1 file changed, 17 insertions(+), 3 deletions(-)
    
    diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp
    index b338404..75c124d 100644
    a b static property_info sPropertyInfo[] = {  
    190190        "Gets the title of the nth track in Playlist.", 0,
    191191        { B_STRING_TYPE }
    192192    },
     193    { "CurrentTrack", { B_GET_PROPERTY, 0 },
     194        { B_DIRECT_SPECIFIER, 0 },
     195        "Gets the pointer to the current track.", 0,
     196        { B_POINTER_TYPE }
     197    },
    193198
    194199    { 0 }
    195200};
    MainWin::MessageReceived(BMessage* msg)  
    622627
    623628                case 14:
    624629                {
    625                     int32 i = specifier.GetInt32("index", 0);
    626                     if (i >= fPlaylist->CountItems()) {
     630                    int32 index = specifier.GetInt32("index", 0);
     631                    if (index >= fPlaylist->CountItems()) {
    627632                        result = B_NO_INIT;
    628633                        break;
    629634                    }
    630635
    631636                    BAutolock _(fPlaylist);
    632                     const PlaylistItem* item = fPlaylist->ItemAt(i);
     637                    const PlaylistItem* item = fPlaylist->ItemAt(index);
    633638                    result = item == NULL ? B_NO_INIT
    634639                        : reply.AddString("result", item->Title());
    635640                    break;
    636641                }
    637642
     643                case 15:
     644                {
     645                    BAutolock _(fPlaylist);
     646                    const PlaylistItem* item = fController->Item();
     647                    result = item == NULL ? B_NO_INIT
     648                        : reply.AddPointer("result", item);
     649                    break;
     650                }
     651
    638652                default:
    639653                    return BWindow::MessageReceived(msg);
    640654            }