From 1aa885efee4a53ef1fcf3db028d70b009fab78fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 28 Oct 2009 16:50:07 +0000 Subject: [PATCH] * Added a temporary solution to add the Audio:Length attribute to audio files, just like SoundPlay did. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33812 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/mediaplayer/MainWin.cpp | 32 +++++++++++++++++++ src/apps/mediaplayer/MainWin.h | 1 + .../mediaplayer/playlist/FilePlaylistItem.h | 2 ++ 3 files changed, 35 insertions(+) diff --git a/src/apps/mediaplayer/MainWin.cpp b/src/apps/mediaplayer/MainWin.cpp index 94ebd5f818..0ae8679864 100644 --- a/src/apps/mediaplayer/MainWin.cpp +++ b/src/apps/mediaplayer/MainWin.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include "AudioProducer.h" #include "ControllerObserver.h" +#include "FilePlaylistItem.h" #include "MainApp.h" #include "PeakView.h" #include "PlaylistItem.h" @@ -442,6 +444,7 @@ MainWin::MessageReceived(BMessage *msg) // TODO: move all other GUI changes as a reaction to this // notification // _UpdatePlaylistMenu(); + _SetFileAttributes(); break; case MSG_CONTROLLER_VIDEO_TRACK_CHANGED: { @@ -1677,6 +1680,35 @@ MainWin::_ToggleNoInterface() // #pragma mark - +/*! Sets some standard attributes of the currently played file. + This should only be a temporary solution. +*/ +void +MainWin::_SetFileAttributes() +{ + const FilePlaylistItem* item + = dynamic_cast(fController->Item()); + + if (!fHasVideo && fHasAudio) { + BNode node(&item->Ref()); + if (node.InitCheck()) + return; + + attr_info info; + status_t status = node.GetAttrInfo("Audio:Length", &info); + if (status != B_OK || info.size == 0) { + time_t duration = fController->TimeDuration() / 1000000L; + + char text[256]; + snprintf(text, sizeof(text), "%02ld:%02ld", duration / 60, + duration % 60); + node.WriteAttr("Audio:Length", B_STRING_TYPE, 0, text, + strlen(text) + 1); + } + } +} + + void MainWin::_UpdateControlsEnabledStatus() { diff --git a/src/apps/mediaplayer/MainWin.h b/src/apps/mediaplayer/MainWin.h index 464bff729d..13ebc63a14 100644 --- a/src/apps/mediaplayer/MainWin.h +++ b/src/apps/mediaplayer/MainWin.h @@ -102,6 +102,7 @@ private: void _ToggleAlwaysOnTop(); void _ToggleNoInterface(); + void _SetFileAttributes(); void _UpdateControlsEnabledStatus(); void _UpdatePlaylistMenu(); void _AddPlaylistItem(PlaylistItem* item, diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.h b/src/apps/mediaplayer/playlist/FilePlaylistItem.h index 725c94007f..7e1017a12c 100644 --- a/src/apps/mediaplayer/playlist/FilePlaylistItem.h +++ b/src/apps/mediaplayer/playlist/FilePlaylistItem.h @@ -50,6 +50,8 @@ public: // playback virtual BMediaFile* CreateMediaFile() const; + const entry_ref& Ref() const { return fRef; } + private: entry_ref fRef; BString fNameInTrash;