1 /* 2 * Copyright 2009-2010 Stephan Aßmus <superstippi@gmx.de> 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 #ifndef PLAYLIST_ITEM_H 6 #define PLAYLIST_ITEM_H 7 8 9 #include <Archivable.h> 10 #include <List.h> 11 #include <NodeInfo.h> 12 #include <Referenceable.h> 13 #include <String.h> 14 15 16 class BBitmap; 17 class BMessage; 18 class TrackSupplier; 19 20 21 class PlaylistItem : public BArchivable, public BReferenceable { 22 public: 23 class Listener { 24 public: 25 Listener(); 26 virtual ~Listener(); 27 28 virtual void ItemChanged(const PlaylistItem* item); 29 }; 30 31 public: 32 PlaylistItem(); 33 virtual ~PlaylistItem(); 34 35 virtual PlaylistItem* Clone() const = 0; 36 37 // archiving 38 virtual status_t Archive(BMessage* into, 39 bool deep = true) const = 0; 40 41 // attributes 42 typedef enum { 43 ATTR_STRING_NAME = 'name', 44 ATTR_STRING_KEYWORDS = 'kwrd', 45 46 ATTR_STRING_ARTIST = 'arst', 47 ATTR_STRING_AUTHOR = 'auth', 48 ATTR_STRING_ALBUM = 'albm', 49 ATTR_STRING_TITLE = 'titl', 50 ATTR_STRING_AUDIO_BITRATE = 'abtr', 51 ATTR_STRING_VIDEO_BITRATE = 'vbtr', 52 53 ATTR_INT32_TRACK = 'trck', 54 ATTR_INT32_YEAR = 'year', 55 ATTR_INT32_RATING = 'rtng', 56 57 ATTR_INT64_DURATION = 'drtn', 58 ATTR_INT64_FRAME = 'fram', 59 ATTR_FLOAT_VOLUME = 'volu' 60 } Attribute; 61 62 virtual status_t SetAttribute(const Attribute& attribute, 63 const BString& string) = 0; 64 virtual status_t GetAttribute(const Attribute& attribute, 65 BString& string) const = 0; 66 67 virtual status_t SetAttribute(const Attribute& attribute, 68 const int32& value) = 0; 69 virtual status_t GetAttribute(const Attribute& attribute, 70 int32& value) const = 0; 71 72 virtual status_t SetAttribute(const Attribute& attribute, 73 const int64& value) = 0; 74 virtual status_t GetAttribute(const Attribute& attribute, 75 int64& value) const = 0; 76 77 virtual status_t SetAttribute(const Attribute& attribute, 78 const float& value) = 0; 79 virtual status_t GetAttribute(const Attribute& attribute, 80 float& value) const = 0; 81 82 // convenience access to attributes 83 BString Name() const; 84 BString Author() const; 85 BString Album() const; 86 BString Title() const; 87 88 int32 TrackNumber() const; 89 90 bigtime_t Duration(); 91 int64 LastFrame() const; 92 float LastVolume() const; 93 94 status_t SetLastFrame(int64 value); 95 status_t SetLastVolume(float value); 96 97 // methods 98 virtual BString LocationURI() const = 0; 99 virtual status_t GetIcon(BBitmap* bitmap, 100 icon_size iconSize) const = 0; 101 102 virtual status_t MoveIntoTrash() = 0; 103 virtual status_t RestoreFromTrash() = 0; 104 105 // Create and return the TrackSupplier if it doesn't exist, 106 // this object is used for media playback. 107 TrackSupplier* GetTrackSupplier(); 108 // Delete and reset the TrackSupplier 109 void ReleaseTrackSupplier(); 110 // Return whether the supplier has been initialized 111 bool HasTrackSupplier() const; 112 113 void SetPlaybackFailed(); 114 bool PlaybackFailed() const 115 { return fPlaybackFailed; } 116 117 // listener support 118 bool AddListener(Listener* listener); 119 void RemoveListener(Listener* listener); 120 121 protected: 122 void _NotifyListeners() const; 123 virtual bigtime_t _CalculateDuration(); 124 virtual TrackSupplier* _CreateTrackSupplier() const = 0; 125 126 private: 127 BList fListeners; 128 bool fPlaybackFailed; 129 TrackSupplier* fTrackSupplier; 130 bigtime_t fDuration; 131 }; 132 133 typedef BReference<PlaylistItem> PlaylistItemRef; 134 135 #endif // PLAYLIST_ITEM_H 136