diff --git a/src/MediaPlayer.cpp b/src/MediaPlayer.cpp index 47983b2..36b8305 100644 --- a/src/MediaPlayer.cpp +++ b/src/MediaPlayer.cpp @@ -152,19 +152,24 @@ MediaPlayer::Window() fWindowTargetHops = kTargetHops; + Song current; + CurrentItem(¤t, false); + for (int32 i = CountWindows() - 1; i >= 0; i--) { MediaPlayer mp(i, MP_BY_INDEX); if (mp.IsValid()) { if (fWindowTarget == MP_BY_LATEST) - return i; + return fWindowIndex = i; - Song current; - BString type; - if (CurrentItem(¤t, false) - && BNode(current.Path().Path()).ReadAttrString("BEOS:TYPE", &type) == B_OK) - if ((type.StartsWith("audio") && fWindowTarget == MP_BY_TYPE_AUDIO) - || (type.StartsWith("video") && fWindowTarget == MP_BY_TYPE_VIDEO)) - return i; + Song mpcurrent; + mp.CurrentItem(&mpcurrent, false); + + // If the current item's type is correct, we'll keep it + if (!current.InitCheck() || !_MatchesTypeTarget(current.Type(), fWindowTarget)) + if (mpcurrent.InitCheck() && _MatchesTypeTarget(mpcurrent.Type(), fWindowTarget)) + return fWindowIndex = i; + else + fWindowIndex = -1; } } return fWindowIndex; @@ -259,6 +264,14 @@ MediaPlayer::_ScriptingCall(const char* attribute, BMessage* send, BMessage* rep } +bool +MediaPlayer::_MatchesTypeTarget(BString mimetype, target typeTarget) +{ + return (mimetype.StartsWith("video") && typeTarget == MP_BY_TYPE_VIDEO) + || (mimetype.StartsWith("audio") && typeTarget == MP_BY_TYPE_AUDIO); +} + + const char* MediaPlayer::_UriToPath(BString URI) { diff --git a/src/MediaPlayer.h b/src/MediaPlayer.h index e7a55d2..7c5255c 100644 --- a/src/MediaPlayer.h +++ b/src/MediaPlayer.h @@ -71,6 +71,7 @@ private: void _ScriptingCall(const char* attribute, BMessage* send, BMessage* reply, int32 trackIndex = MP_NO_TRACK, bool window = true); + bool _MatchesTypeTarget(BString mimetype, target typeTarget); const char* _UriToPath(BString URI); int32 fWindowIndex; diff --git a/src/Song.cpp b/src/Song.cpp index e300ade..3865323 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -75,6 +75,15 @@ Song::Path() } +BString +Song::Type() +{ + if (fType.IsEmpty()) + BNode(fPath.Path()).ReadAttrString("BEOS:TYPE", &fType); + return fType; +} + + int64 Song::Duration() { diff --git a/src/Song.h b/src/Song.h index 6fecebd..d36f21e 100644 --- a/src/Song.h +++ b/src/Song.h @@ -18,6 +18,7 @@ #define SONG_H #include +#include class BBitmap; @@ -32,6 +33,7 @@ public: BBitmap* Cover(); BPath Path(); + BString Type(); int64 Duration(); int operator ==(Song a) @@ -60,6 +62,7 @@ private: int64 fDuration; BPath fPath; + BString fType; }; #endif // SONG_H