repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / mediaplayer / playlist / UrlPlaylistItem.cpp
blob5f2fbc2b653025903f0ba8928a0b4db48e92c1fe
1 /*
2 * Copyright 2016, Dario Casalinuovo
3 * All rights reserved. Distributed under the terms of the MIT license.
4 */
7 #include "UrlPlaylistItem.h"
9 #include <MediaFile.h>
10 #include <MediaTrack.h>
12 #include "MediaFileTrackSupplier.h"
15 UrlPlaylistItem::UrlPlaylistItem(BUrl url)
17 fUrl(url),
18 fDuration(-1)
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)
33 fUrl = BUrl(url);
37 UrlPlaylistItem::~UrlPlaylistItem()
42 PlaylistItem*
43 UrlPlaylistItem::Clone() const
45 return new UrlPlaylistItem(fUrl);
49 BArchivable*
50 UrlPlaylistItem::Instantiate(BMessage* archive)
52 if (validate_instantiation(archive, "UrlPlaylistItem"))
53 return new (std::nothrow) UrlPlaylistItem(archive);
55 return NULL;
59 status_t
60 UrlPlaylistItem::Archive(BMessage* into, bool deep) const
62 return into->AddString("mediaplayer:url", fUrl.UrlString());
66 status_t
67 UrlPlaylistItem::SetAttribute(const Attribute& attribute, const BString& string)
69 return B_ERROR;
73 status_t
74 UrlPlaylistItem::GetAttribute(const Attribute& attribute, BString& string) const
76 if (attribute == ATTR_STRING_NAME) {
77 string = fUrl.UrlString();
78 return B_OK;
81 return B_NOT_SUPPORTED;
85 status_t
86 UrlPlaylistItem::SetAttribute(const Attribute& attribute, const int32& value)
88 return B_NOT_SUPPORTED;
92 status_t
93 UrlPlaylistItem::GetAttribute(const Attribute& attribute, int32& value) const
95 return B_NOT_SUPPORTED;
99 status_t
100 UrlPlaylistItem::SetAttribute(const Attribute& attribute, const int64& value)
102 return B_NOT_SUPPORTED;
106 status_t
107 UrlPlaylistItem::GetAttribute(const Attribute& attribute, int64& value) const
109 if (attribute == ATTR_INT64_DURATION && fDuration >= 0) {
110 value = fDuration;
111 return B_OK;
113 return B_NOT_SUPPORTED;
117 BString
118 UrlPlaylistItem::LocationURI() const
120 return fUrl.UrlString();
124 status_t
125 UrlPlaylistItem::GetIcon(BBitmap* bitmap, icon_size iconSize) const
127 return B_NOT_SUPPORTED;
131 status_t
132 UrlPlaylistItem::MoveIntoTrash()
134 return B_NOT_SUPPORTED;
138 status_t
139 UrlPlaylistItem::RestoreFromTrash()
141 return B_NOT_SUPPORTED;
145 bigtime_t
146 UrlPlaylistItem::_CalculateDuration()
148 if (fDuration < 0) {
149 BMediaFile mediaFile(fUrl);
151 if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() < 1)
152 return 0;
153 fDuration = mediaFile.TrackAt(0)->Duration();
155 return fDuration;
159 TrackSupplier*
160 UrlPlaylistItem::_CreateTrackSupplier() const
162 MediaFileTrackSupplier* supplier
163 = new(std::nothrow) MediaFileTrackSupplier();
164 if (supplier == NULL)
165 return NULL;
167 BMediaFile* mediaFile = new(std::nothrow) BMediaFile(fUrl);
168 if (mediaFile == NULL || supplier->AddMediaFile(mediaFile) != B_OK) {
169 delete mediaFile;
170 delete supplier;
171 return NULL;
174 return supplier;
178 BUrl
179 UrlPlaylistItem::Url() const
181 return fUrl;