Use new MediaPlayer scripting hooks; formatting

By formatting, I mean superfluous == trues.
By scripting hooks, I mean CurrentTrack/PLaylistTrack.
This commit is contained in:
Jaidyn Ann 2022-05-19 09:31:02 -05:00
parent a4c1635962
commit 6a7ed4b302
3 changed files with 19 additions and 15 deletions

View File

@ -67,7 +67,7 @@ CoverView::Pulse()
delete fCover; delete fCover;
fCover = song.Cover(); fCover = song.Cover();
Invalidate(); Invalidate();
} else if (path.IsEmpty() == true && path != fCurrentPath) { } else if (path.IsEmpty() && path != fCurrentPath) {
fCurrentPath = path; fCurrentPath = path;
delete fCover; delete fCover;
Invalidate(); Invalidate();
@ -80,7 +80,7 @@ CoverView::Draw(BRect updateRect)
{ {
BView::Draw(updateRect); BView::Draw(updateRect);
if (fCover != NULL) if (fCover != NULL && fCover->IsValid())
DrawBitmap(fCover, Bounds()); DrawBitmap(fCover, Bounds());
} }
@ -91,6 +91,7 @@ CoverView::_GetCurrentPath()
BMessage message, reply; BMessage message, reply;
message.what = B_GET_PROPERTY; message.what = B_GET_PROPERTY;
message.AddSpecifier("URI"); message.AddSpecifier("URI");
message.AddSpecifier("CurrentTrack");
message.AddSpecifier("Window", 0); message.AddSpecifier("Window", 0);
BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply); BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply);

View File

@ -178,7 +178,7 @@ LyricsView::MessageReceived(BMessage* msg)
if (msg->what == LYRICS_TRANSPARENTLY_DRAG) if (msg->what == LYRICS_TRANSPARENTLY_DRAG)
fTransparentDragger = !fTransparentDragger; fTransparentDragger = !fTransparentDragger;
if (fCurrentPath.IsEmpty() == true) if (fCurrentPath.IsEmpty())
_ClearText(); _ClearText();
break; break;
} }
@ -199,12 +199,12 @@ LyricsView::Pulse()
BString lyrics; BString lyrics;
song.Lyrics(&lyrics); song.Lyrics(&lyrics);
_SetText(lyrics.String()); _SetText(lyrics.String());
} else if (path.IsEmpty() == true && path != fCurrentPath) { } else if (path.IsEmpty() && path != fCurrentPath) {
fCurrentPath = path; fCurrentPath = path;
_ClearText(); _ClearText();
} }
if (fAutoScroll == true) { if (fAutoScroll) {
float position = _GetPositionProportion(); float position = _GetPositionProportion();
if (position > 0) if (position > 0)
fTextView->ScrollToOffset(fTextView->TextLength() * position); fTextView->ScrollToOffset(fTextView->TextLength() * position);
@ -235,9 +235,9 @@ LyricsView::_Init(BRect frame)
void void
LyricsView::_SetText(const char* text) LyricsView::_SetText(const char* text)
{ {
if (fScrollView->IsHidden() == true) if (fScrollView->IsHidden())
fScrollView->Show(); fScrollView->Show();
if (fDragger->IsHidden() == true) if (fDragger->IsHidden())
fDragger->Show(); fDragger->Show();
fTextView->SetText(text); fTextView->SetText(text);
@ -248,15 +248,15 @@ LyricsView::_SetText(const char* text)
void void
LyricsView::_ClearText() LyricsView::_ClearText()
{ {
if (fTransparentInactivity == true) { if (fTransparentInactivity) {
if (fScrollView->IsHidden() == false) if (fScrollView->IsHidden())
fScrollView->Hide(); fScrollView->Hide();
if (fDragger->IsHidden() == false && fTransparentDragger == true) if (fDragger->IsHidden() && fTransparentDragger)
fDragger->Hide(); fDragger->Hide();
} else { } else {
if (fScrollView->IsHidden() == true) if (fScrollView->IsHidden())
fScrollView->Show(); fScrollView->Show();
if (fDragger->IsHidden() == true) if (fDragger->IsHidden())
fDragger->Show(); fDragger->Show();
} }
@ -340,6 +340,7 @@ LyricsView::_GetCurrentPath()
BMessage message, reply; BMessage message, reply;
message.what = B_GET_PROPERTY; message.what = B_GET_PROPERTY;
message.AddSpecifier("URI"); message.AddSpecifier("URI");
message.AddSpecifier("CurrentTrack");
message.AddSpecifier("Window", 0); message.AddSpecifier("Window", 0);
BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply); BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply);
@ -353,7 +354,7 @@ float
LyricsView::_GetPositionProportion() LyricsView::_GetPositionProportion()
{ {
int64 position = _GetIntProperty("Position"); int64 position = _GetIntProperty("Position");
int64 duration = _GetIntProperty("Duration"); int64 duration = _GetIntProperty("Duration", true);
if (position >= 0 && duration > 0) if (position >= 0 && duration > 0)
return (float)position / (float)duration; return (float)position / (float)duration;
return -1.0; return -1.0;
@ -361,11 +362,13 @@ LyricsView::_GetPositionProportion()
int64 int64
LyricsView::_GetIntProperty(const char* specifier) LyricsView::_GetIntProperty(const char* specifier, bool currentItem)
{ {
BMessage message, reply; BMessage message, reply;
message.what = B_GET_PROPERTY; message.what = B_GET_PROPERTY;
message.AddSpecifier(specifier); message.AddSpecifier(specifier);
if (currentItem)
message.AddSpecifier("CurrentTrack");
message.AddSpecifier("Window", 0); message.AddSpecifier("Window", 0);
BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply); BMessenger("application/x-vnd.Haiku-MediaPlayer").SendMessage(&message, &reply);

View File

@ -57,7 +57,7 @@ private:
BString _GetCurrentPath(); BString _GetCurrentPath();
float _GetPositionProportion(); float _GetPositionProportion();
int64 _GetIntProperty(const char* specifier); int64 _GetIntProperty(const char* specifier, bool currentTrack = false);
LyricsTextView* fTextView; LyricsTextView* fTextView;
BScrollView* fScrollView; BScrollView* fScrollView;