MediaPlayer: Show individual track length in playlist window
Signed-off-by: Dario Casalinuovo <[email protected]>
This commit is contained in:
committed by
Dario Casalinuovo
parent
b259ac9c59
commit
b5387eff2b
@@ -13,6 +13,7 @@
|
||||
#include <File.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <MediaFile.h>
|
||||
#include <MediaTrack.h>
|
||||
#include <Path.h>
|
||||
#include <TranslationUtils.h>
|
||||
|
||||
@@ -398,6 +399,18 @@ FilePlaylistItem::ImageRef() const
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
FilePlaylistItem::_CalculateDuration() const
|
||||
{
|
||||
BMediaFile mediaFile(&Ref());
|
||||
|
||||
if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() < 1)
|
||||
return 0;
|
||||
|
||||
return mediaFile.TrackAt(0)->Duration();
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
FilePlaylistItem::_SetAttribute(const char* attrName, type_code type,
|
||||
const void* data, size_t size)
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
status_t AddImageRef(const entry_ref& ref);
|
||||
const entry_ref& ImageRef() const;
|
||||
|
||||
protected:
|
||||
virtual bigtime_t _CalculateDuration() const;
|
||||
|
||||
private:
|
||||
status_t _SetAttribute(const char* attrName,
|
||||
type_code type, const void* data,
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
#include <Catalog.h>
|
||||
#include <Locale.h>
|
||||
|
||||
#include "AudioTrackSupplier.h"
|
||||
#include "TrackSupplier.h"
|
||||
#include "VideoTrackSupplier.h"
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistItem"
|
||||
@@ -107,6 +110,19 @@ PlaylistItem::TrackNumber() const
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
PlaylistItem::Duration()
|
||||
{
|
||||
bigtime_t duration;
|
||||
if (GetAttribute(ATTR_INT64_DURATION, duration) != B_OK) {
|
||||
duration = this->_CalculateDuration();
|
||||
SetAttribute(ATTR_INT64_DURATION, duration);
|
||||
}
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistItem::SetPlaybackFailed()
|
||||
{
|
||||
@@ -143,3 +159,22 @@ PlaylistItem::_NotifyListeners() const
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bigtime_t PlaylistItem::_CalculateDuration() const
|
||||
{
|
||||
// To be overridden in subclasses with more efficient methods
|
||||
TrackSupplier* supplier = CreateTrackSupplier();
|
||||
|
||||
AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0);
|
||||
VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0);
|
||||
|
||||
bigtime_t duration = max_c(au == NULL ? 0 : au->Duration(),
|
||||
vi == NULL ? 0 : vi->Duration());
|
||||
|
||||
delete vi;
|
||||
delete au;
|
||||
delete supplier;
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public:
|
||||
|
||||
int32 TrackNumber() const;
|
||||
|
||||
bigtime_t Duration();
|
||||
|
||||
// methods
|
||||
virtual BString LocationURI() const = 0;
|
||||
virtual status_t GetIcon(BBitmap* bitmap,
|
||||
@@ -101,6 +103,7 @@ public:
|
||||
|
||||
protected:
|
||||
void _NotifyListeners() const;
|
||||
virtual bigtime_t _CalculateDuration() const;
|
||||
|
||||
private:
|
||||
BList fListeners;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "Controller.h"
|
||||
#include "ControllerObserver.h"
|
||||
#include "CopyPLItemsCommand.h"
|
||||
#include "DurationToString.h"
|
||||
#include "ImportPLItemsCommand.h"
|
||||
#include "ListViews.h"
|
||||
#include "MovePLItemsCommand.h"
|
||||
@@ -132,9 +133,22 @@ PlaylistListView::Item::Draw(BView* owner, BRect frame, const font_height& fh,
|
||||
float playbackMarkSize = playback_mark_size(fh);
|
||||
float textOffset = text_offset(fh);
|
||||
|
||||
char buffer[64];
|
||||
bigtime_t duration = fItem->Duration();
|
||||
duration /= 1000000;
|
||||
duration_to_string(duration, buffer, sizeof(buffer));
|
||||
|
||||
BString truncatedDuration(buffer);
|
||||
owner->TruncateString(&truncatedDuration, B_TRUNCATE_END,
|
||||
frame.Width() - playbackMarkSize - textOffset);
|
||||
float truncatedWidth = owner->StringWidth(truncatedDuration.String());
|
||||
owner->DrawString(truncatedDuration.String(),
|
||||
BPoint(frame.right - truncatedWidth,
|
||||
floorf(frame.top + frame.bottom + fh.ascent) / 2 - 1));
|
||||
|
||||
BString truncatedString(text);
|
||||
owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE,
|
||||
frame.Width() - playbackMarkSize - textOffset);
|
||||
frame.Width() - playbackMarkSize - textOffset - truncatedWidth);
|
||||
owner->DrawString(truncatedString.String(),
|
||||
BPoint(frame.left + playbackMarkSize + textOffset,
|
||||
floorf(frame.top + frame.bottom + fh.ascent) / 2 - 1));
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include <File.h>
|
||||
#include <FilePanel.h>
|
||||
#include <Locale.h>
|
||||
#include <MediaFile.h>
|
||||
#include <MediaTrack.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
@@ -35,14 +33,11 @@
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
|
||||
#include "AudioTrackSupplier.h"
|
||||
#include "CommandStack.h"
|
||||
#include "DurationToString.h"
|
||||
#include "MainApp.h"
|
||||
#include "PlaylistListView.h"
|
||||
#include "RWLocker.h"
|
||||
#include "TrackSupplier.h"
|
||||
#include "VideoTrackSupplier.h"
|
||||
|
||||
#undef B_TRANSLATION_CONTEXT
|
||||
#define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistWindow"
|
||||
@@ -548,7 +543,7 @@ void
|
||||
PlaylistWindow::DurationListener::_HandleItemAdded(PlaylistItem* item,
|
||||
int32 index)
|
||||
{
|
||||
bigtime_t duration = _DetermineItemDuration(item);
|
||||
bigtime_t duration = item->Duration();
|
||||
fTotalDuration += duration;
|
||||
fParent._UpdateTotalDuration(fTotalDuration);
|
||||
fKnown.AddItem(new bigtime_t(duration), index);
|
||||
@@ -568,41 +563,3 @@ PlaylistWindow::DurationListener::_HandleItemRemoved(int32 index)
|
||||
delete deleted;
|
||||
}
|
||||
|
||||
|
||||
bigtime_t
|
||||
PlaylistWindow::DurationListener::_DetermineItemDuration(PlaylistItem* item)
|
||||
{
|
||||
bigtime_t duration;
|
||||
if (item->GetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration) == B_OK)
|
||||
return duration;
|
||||
|
||||
// We have to find out the duration ourselves
|
||||
if (FilePlaylistItem* file = dynamic_cast<FilePlaylistItem*>(item)) {
|
||||
// We are dealing with a file
|
||||
BMediaFile mediaFile(&file->Ref());
|
||||
|
||||
if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() < 1)
|
||||
return 0;
|
||||
|
||||
duration = mediaFile.TrackAt(0)->Duration();
|
||||
} else {
|
||||
// Not a file, so fall back to the generic TrackSupplier solution
|
||||
TrackSupplier* supplier = item->CreateTrackSupplier();
|
||||
|
||||
AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0);
|
||||
VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0);
|
||||
|
||||
duration = max_c(au == NULL ? 0 : au->Duration(),
|
||||
vi == NULL ? 0 : vi->Duration());
|
||||
|
||||
delete vi;
|
||||
delete au;
|
||||
delete supplier;
|
||||
}
|
||||
|
||||
// Store the duration for later use
|
||||
item->SetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration);
|
||||
|
||||
return duration;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ private:
|
||||
void _HandleItemAdded(PlaylistItem* item,
|
||||
int32 index);
|
||||
void _HandleItemRemoved(int32 index);
|
||||
bigtime_t _DetermineItemDuration(PlaylistItem* item);
|
||||
|
||||
BObjectList<bigtime_t>
|
||||
fKnown;
|
||||
|
||||
Reference in New Issue
Block a user