2 * Copyright 2016, Dario Casalinuovo
3 * All rights reserved. Distributed under the terms of the MIT license.
7 #include "UrlPlaylistItem.h"
10 #include <MediaTrack.h>
12 #include "MediaFileTrackSupplier.h"
15 UrlPlaylistItem::UrlPlaylistItem(BUrl url
)
23 UrlPlaylistItem::UrlPlaylistItem(const UrlPlaylistItem
& item
)
25 fUrl
= BUrl(item
.Url());
29 UrlPlaylistItem::UrlPlaylistItem(const BMessage
* archive
)
31 const char* url
= NULL
;
32 if (archive
->FindString("mediaplayer:url", &url
) == B_OK
)
37 UrlPlaylistItem::~UrlPlaylistItem()
43 UrlPlaylistItem::Clone() const
45 return new UrlPlaylistItem(fUrl
);
50 UrlPlaylistItem::Instantiate(BMessage
* archive
)
52 if (validate_instantiation(archive
, "UrlPlaylistItem"))
53 return new (std::nothrow
) UrlPlaylistItem(archive
);
60 UrlPlaylistItem::Archive(BMessage
* into
, bool deep
) const
62 return into
->AddString("mediaplayer:url", fUrl
.UrlString());
67 UrlPlaylistItem::SetAttribute(const Attribute
& attribute
, const BString
& string
)
74 UrlPlaylistItem::GetAttribute(const Attribute
& attribute
, BString
& string
) const
76 if (attribute
== ATTR_STRING_NAME
) {
77 string
= fUrl
.UrlString();
81 return B_NOT_SUPPORTED
;
86 UrlPlaylistItem::SetAttribute(const Attribute
& attribute
, const int32
& value
)
88 return B_NOT_SUPPORTED
;
93 UrlPlaylistItem::GetAttribute(const Attribute
& attribute
, int32
& value
) const
95 return B_NOT_SUPPORTED
;
100 UrlPlaylistItem::SetAttribute(const Attribute
& attribute
, const int64
& value
)
102 return B_NOT_SUPPORTED
;
107 UrlPlaylistItem::GetAttribute(const Attribute
& attribute
, int64
& value
) const
109 if (attribute
== ATTR_INT64_DURATION
&& fDuration
>= 0) {
113 return B_NOT_SUPPORTED
;
118 UrlPlaylistItem::LocationURI() const
120 return fUrl
.UrlString();
125 UrlPlaylistItem::GetIcon(BBitmap
* bitmap
, icon_size iconSize
) const
127 return B_NOT_SUPPORTED
;
132 UrlPlaylistItem::MoveIntoTrash()
134 return B_NOT_SUPPORTED
;
139 UrlPlaylistItem::RestoreFromTrash()
141 return B_NOT_SUPPORTED
;
146 UrlPlaylistItem::_CalculateDuration()
149 BMediaFile
mediaFile(fUrl
);
151 if (mediaFile
.InitCheck() != B_OK
|| mediaFile
.CountTracks() < 1)
153 fDuration
= mediaFile
.TrackAt(0)->Duration();
160 UrlPlaylistItem::_CreateTrackSupplier() const
162 MediaFileTrackSupplier
* supplier
163 = new(std::nothrow
) MediaFileTrackSupplier();
164 if (supplier
== NULL
)
167 BMediaFile
* mediaFile
= new(std::nothrow
) BMediaFile(fUrl
);
168 if (mediaFile
== NULL
|| supplier
->AddMediaFile(mediaFile
) != B_OK
) {
179 UrlPlaylistItem::Url() const