Ticket #1503: mediaplayer-volume-memory.diff

File mediaplayer-volume-memory.diff, 4.3 KB (added by engleek, 14 years ago)

First efforts at addressing this enhancement.

  • src/apps/mediaplayer/MainWin.cpp

     
    587587            PlaylistItemRef item(fPlaylist->ItemAt(index));
    588588            if (item.Get() != NULL) {
    589589                printf("open playlist item: %s\n", item->Name().String());
     590                printf("\n ! Save current volume last played item\n");
     591                if (fLatestPlaylistItem != NULL) {
     592                    if (fLatestPlaylistItem->SetVolume(fController->Volume()) != B_OK) {
     593                        printf(" !  SetVolume failed.");
     594                    } else {
     595                        printf(" !  Volume set to %i", (int)fLatestPlaylistItem->Volume());
     596                    }
     597                }
    590598                OpenPlaylistItem(item);
     599                fLatestPlaylistItem = fPlaylist->ItemAt(index);
     600                printf("\n ! Load item volume\n");
     601                if (fLatestPlaylistItem->Volume() != -1) {
     602                    fController->SetVolume((float)fLatestPlaylistItem->Volume());
     603                    printf(" !  Loading volume: %i", (int)fLatestPlaylistItem->Volume());
     604                }
    591605                _MarkPlaylistItem(index);
    592606            }
    593607            break;
  • src/apps/mediaplayer/MainWin.h

     
    152152            bool                fHasAudio;
    153153
    154154            Playlist*           fPlaylist;
     155            PlaylistItem*       fLatestPlaylistItem;
    155156            PlaylistObserver*   fPlaylistObserver;
    156157            Controller*         fController;
    157158            ControllerObserver* fControllerObserver;
  • src/apps/mediaplayer/playlist/FilePlaylistItem.cpp

     
    127127FilePlaylistItem::SetAttribute(const Attribute& attribute,
    128128    const int64& value)
    129129{
     130    if (attribute == ATTR_INT64_VOLUME) {
     131        BNode node(&fRef);
     132        return node.WriteAttr("mediaplayer:volume", B_INT64_TYPE, 0, &value, sizeof(value));
     133    }
     134
    130135    return B_NOT_SUPPORTED;
    131136}
    132137
     
    135140FilePlaylistItem::GetAttribute(const Attribute& attribute,
    136141    int64& value) const
    137142{
     143    if (attribute == ATTR_INT64_VOLUME) {
     144        BNode node(&fRef);
     145        return node.ReadAttr("mediaplayer:volume", B_INT64_TYPE, 0, &value, sizeof(value));
     146    }
     147
    138148    return B_NOT_SUPPORTED;
    139149}
    140150
     
    298308    return new (std::nothrow) BMediaFile(&fRef);
    299309}
    300310
     311
     312status_t
     313FilePlaylistItem::SetVolume(int64 volume)
     314{
     315    return SetAttribute(ATTR_INT64_VOLUME, volume);
     316}
  • src/apps/mediaplayer/playlist/PlaylistItem.cpp

     
    120120}
    121121
    122122
     123int64
     124PlaylistItem::Volume() const
     125{
     126    int64 volume;
     127    if (GetAttribute(ATTR_INT64_VOLUME, volume) != B_OK)
     128        volume = -1;
     129    return volume;
     130}
     131
     132
    123133void
    124134PlaylistItem::SetPlaybackFailed()
    125135{
  • src/apps/mediaplayer/playlist/PlaylistItem.h

     
    5050        ATTR_INT32_RATING       = 'rtng',
    5151        ATTR_INT32_BIT_RATE     = 'btrt',
    5252
    53         ATTR_INT64_DURATION     = 'drtn'
     53        ATTR_INT64_DURATION     = 'drtn',
     54
     55        ATTR_INT64_VOLUME       = 'volu'
    5456    } Attribute;
    5557
    5658    virtual status_t            SetAttribute(const Attribute& attribute,
     
    7981
    8082            bigtime_t           Duration() const;
    8183
     84            int64               Volume() const;
     85
    8286    // methods
    8387    virtual BString             LocationURI() const = 0;
    8488    virtual status_t            GetIcon(BBitmap* bitmap,
     
    8791    virtual status_t            MoveIntoTrash() = 0;
    8892    virtual status_t            RestoreFromTrash() = 0;
    8993
     94    virtual status_t            SetVolume(int64 volume) = 0;
     95
    9096    // playback
    9197    virtual BMediaFile*         CreateMediaFile() const = 0;
    9298
  • src/apps/mediaplayer/playlist/FilePlaylistItem.h

     
    4747    virtual status_t            MoveIntoTrash();
    4848    virtual status_t            RestoreFromTrash();
    4949
     50    virtual status_t            SetVolume(int64 volume);
     51
    5052    // playback
    5153    virtual BMediaFile*         CreateMediaFile() const;
    5254