Ticket #6564: mediaplayer.3.patch
File mediaplayer.3.patch, 12.1 KB (added by , 8 years ago) |
---|
-
src/apps/mediaplayer/Controller.cpp
From efa517ddd0c16099cc06145f15f6f842f0c66399 Mon Sep 17 00:00:00 2001 From: Markus Himmel <markus@himmel-villmar.de> Date: Mon, 4 Jan 2016 23:06:28 +0100 Subject: [PATCH 1/2] MediaPlayer: Add missing null check --- src/apps/mediaplayer/Controller.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/apps/mediaplayer/Controller.cpp b/src/apps/mediaplayer/Controller.cpp index 5176a3d..f555cc8 100644
a b Controller::SetTo(const PlaylistItemRef& item) 302 302 trackSupplierDeleter.Detach(); 303 303 304 304 // prevent blocking the creation of new overlay buffers 305 fVideoView->DisableOverlay(); 305 if (fVideoView) 306 fVideoView->DisableOverlay(); 306 307 307 308 // get video properties (if there is video at all) 308 309 bool useOverlays = fVideoView ? fVideoView->UseOverlays() : true; -
src/apps/mediaplayer/playlist/FilePlaylistItem.cpp
-- 2.2.2 From b0c524d4655fa917f90466857e5450091885ae3a Mon Sep 17 00:00:00 2001 From: Markus Himmel <markus@himmel-villmar.de> Date: Mon, 4 Jan 2016 23:08:04 +0100 Subject: [PATCH 2/2] MediaPlayer: Show total playlist length --- src/apps/mediaplayer/playlist/FilePlaylistItem.cpp | 18 +- src/apps/mediaplayer/playlist/FilePlaylistItem.h | 2 +- src/apps/mediaplayer/playlist/PlaylistItem.h | 5 +- src/apps/mediaplayer/playlist/PlaylistWindow.cpp | 187 ++++++++++++++++++++- src/apps/mediaplayer/playlist/PlaylistWindow.h | 34 +++- 5 files changed, 236 insertions(+), 10 deletions(-) diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp b/src/apps/mediaplayer/playlist/FilePlaylistItem.cpp index 4b1cafd..9279fe1 100644
a b status_t 190 190 FilePlaylistItem::SetAttribute(const Attribute& attribute, 191 191 const int64& value) 192 192 { 193 return B_NOT_SUPPORTED; 193 switch (attribute) { 194 case ATTR_INT64_DURATION: 195 return _SetAttribute("Media:Length", B_INT64_TYPE, &value, 196 sizeof(int64)); 197 default: 198 return B_NOT_SUPPORTED; 199 } 194 200 } 195 201 196 202 … … status_t 198 204 FilePlaylistItem::GetAttribute(const Attribute& attribute, 199 205 int64& value) const 200 206 { 201 return B_NOT_SUPPORTED; 207 switch (attribute) { 208 case ATTR_INT64_DURATION: 209 return _GetAttribute("Media:Length", B_INT64_TYPE, &value, 210 sizeof(int64)); 211 default: 212 return B_NOT_SUPPORTED; 213 } 202 214 } 203 215 204 216 … … FilePlaylistItem::_SetAttribute(const char* attrName, type_code type, 407 419 408 420 status_t 409 421 FilePlaylistItem::_GetAttribute(const char* attrName, type_code type, 410 void* data, size_t size) 422 void* data, size_t size) const 411 423 { 412 424 BEntry entry(&fRefs[0], true); 413 425 BNode node(&entry); -
src/apps/mediaplayer/playlist/FilePlaylistItem.h
diff --git a/src/apps/mediaplayer/playlist/FilePlaylistItem.h b/src/apps/mediaplayer/playlist/FilePlaylistItem.h index a0c4da4..fb72f9e 100644
a b private: 67 67 size_t size); 68 68 status_t _GetAttribute(const char* attrName, 69 69 type_code type, void* data, 70 size_t size) ;70 size_t size) const; 71 71 status_t _MoveIntoTrash(vector<entry_ref>* refs, 72 72 vector<BString>* namesInTrash); 73 73 status_t _RestoreFromTrash(vector<entry_ref>* refs, -
src/apps/mediaplayer/playlist/PlaylistItem.h
diff --git a/src/apps/mediaplayer/playlist/PlaylistItem.h b/src/apps/mediaplayer/playlist/PlaylistItem.h index b896df5..73de81a 100644
a b public: 49 49 ATTR_STRING_TITLE = 'titl', 50 50 ATTR_STRING_AUDIO_BITRATE = 'abtr', 51 51 ATTR_STRING_VIDEO_BITRATE = 'vbtr', 52 ATTR_STRING_DURATION = 'drtn',53 52 54 53 ATTR_INT32_TRACK = 'trck', 55 54 ATTR_INT32_YEAR = 'year', 56 ATTR_INT32_RATING = 'rtng' 55 ATTR_INT32_RATING = 'rtng', 56 57 ATTR_INT64_DURATION = 'drtn' 57 58 } Attribute; 58 59 59 60 virtual status_t SetAttribute(const Attribute& attribute, -
src/apps/mediaplayer/playlist/PlaylistWindow.cpp
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp index 08ce627..fbea517 100644
a b 22 22 #include <File.h> 23 23 #include <FilePanel.h> 24 24 #include <Locale.h> 25 #include <MediaFile.h> 26 #include <MediaTrack.h> 25 27 #include <Menu.h> 26 28 #include <MenuBar.h> 27 29 #include <MenuItem.h> … … 31 33 #include <ScrollBar.h> 32 34 #include <ScrollView.h> 33 35 #include <String.h> 36 #include <StringView.h> 34 37 38 #include "AudioTrackSupplier.h" 35 39 #include "CommandStack.h" 40 #include "DurationToString.h" 36 41 #include "MainApp.h" 37 42 #include "PlaylistListView.h" 38 43 #include "RWLocker.h" 39 44 #include "TrackSupplier.h" 45 #include "VideoTrackSupplier.h" 40 46 41 47 #undef B_TRANSLATION_CONTEXT 42 48 #define B_TRANSLATION_CONTEXT "MediaPlayer-PlaylistWindow" … … PlaylistWindow::PlaylistWindow(BRect frame, Playlist* playlist, 82 88 fPlaylist(playlist), 83 89 fLocker(new RWLocker("command stack lock")), 84 90 fCommandStack(new CommandStack(fLocker)), 85 fCommandStackListener(this) 91 fCommandStackListener(this), 92 fDurationListener(new DurationListener(*this)) 86 93 { 87 94 frame = Bounds(); 88 95 … … PlaylistWindow::PlaylistWindow(BRect frame, Playlist* playlist, 90 97 // will adjust frame to account for menubar 91 98 92 99 frame.right -= B_V_SCROLL_BAR_WIDTH; 100 frame.bottom -= B_H_SCROLL_BAR_HEIGHT; 93 101 fListView = new PlaylistListView(frame, playlist, controller, 94 102 fCommandStack); 95 103 … … PlaylistWindow::PlaylistWindow(BRect frame, Playlist* playlist, 104 112 // make it so the frame of the menubar is also the frame of 105 113 // the scroll bar (appears to be) 106 114 scrollBar->MoveBy(0, -1); 107 scrollBar->ResizeBy(0, -(B_H_SCROLL_BAR_HEIGHT - 2)); 115 scrollBar->ResizeBy(0, 2); 116 } 117 118 frame.top += frame.Height(); 119 frame.bottom += B_H_SCROLL_BAR_HEIGHT; 120 121 fTotalDuration = new BStringView(frame, "fDuration", "", 122 B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); 123 AddChild(fTotalDuration); 124 125 _UpdateTotalDuration(0); 126 127 { 128 BAutolock _(fPlaylist); 129 130 _QueryInitialDurations(); 131 fPlaylist->AddListener(fDurationListener); 108 132 } 109 133 110 134 fCommandStack->AddListener(&fCommandStackListener); … … PlaylistWindow::~PlaylistWindow() 121 145 fCommandStack->RemoveListener(&fCommandStackListener); 122 146 delete fCommandStack; 123 147 delete fLocker; 148 149 fPlaylist->RemoveListener(fDurationListener); 150 BMessenger(fDurationListener).SendMessage(B_QUIT_REQUESTED); 124 151 } 125 152 126 153 … … PlaylistWindow::_SavePlaylist(BEntry& origEntry, BEntry& tempEntry, 422 449 info.SetType("application/x-vnd.haiku-playlist"); 423 450 } 424 451 452 453 void 454 PlaylistWindow::_QueryInitialDurations() 455 { 456 BAutolock lock(fPlaylist); 457 458 BMessage addMessage(MSG_PLAYLIST_ITEM_ADDED); 459 for (int32 i = 0; i < fPlaylist->CountItems(); i++) { 460 addMessage.AddPointer("item", fPlaylist->ItemAt(i)); 461 addMessage.AddInt32("index", i); 462 } 463 464 BMessenger(fDurationListener).SendMessage(&addMessage); 465 } 466 467 468 void 469 PlaylistWindow::_UpdateTotalDuration(bigtime_t duration) 470 { 471 BAutolock lock(this); 472 473 char buffer[64]; 474 duration /= 1000000; 475 duration_to_string(duration, buffer, sizeof(buffer)); 476 477 BString text; 478 text.SetToFormat(B_TRANSLATE("Total duration : %s"), buffer); 479 480 fTotalDuration->SetText(text.String()); 481 } 482 483 484 // #pragma mark - 485 486 487 PlaylistWindow::DurationListener::DurationListener(PlaylistWindow& parent) 488 : 489 PlaylistObserver(this), 490 fKnown(20, true), 491 fTotalDuration(0), 492 fParent(parent) 493 { 494 Run(); 495 } 496 497 498 PlaylistWindow::DurationListener::~DurationListener() 499 { 500 } 501 502 503 void 504 PlaylistWindow::DurationListener::MessageReceived(BMessage* message) 505 { 506 switch (message->what) { 507 case MSG_PLAYLIST_ITEM_ADDED: 508 { 509 void* item; 510 int32 index; 511 512 int32 currentItem = 0; 513 while (message->FindPointer("item", currentItem, &item) == B_OK 514 && message->FindInt32("index", currentItem, &index) == B_OK) { 515 _HandleItemAdded(static_cast<PlaylistItem*>(item), index); 516 ++currentItem; 517 } 518 519 break; 520 } 521 522 case MSG_PLAYLIST_ITEM_REMOVED: 523 { 524 int32 index; 525 526 if (message->FindInt32("index", &index) == B_OK) { 527 _HandleItemRemoved(index); 528 } 529 530 break; 531 } 532 533 default: 534 BLooper::MessageReceived(message); 535 break; 536 } 537 } 538 539 540 bigtime_t 541 PlaylistWindow::DurationListener::TotalDuration() 542 { 543 return fTotalDuration; 544 } 545 546 547 void 548 PlaylistWindow::DurationListener::_HandleItemAdded(PlaylistItem* item, 549 int32 index) 550 { 551 bigtime_t duration = _DetermineItemDuration(item); 552 fTotalDuration += duration; 553 fParent._UpdateTotalDuration(fTotalDuration); 554 fKnown.AddItem(new bigtime_t(duration), index); 555 } 556 557 558 void 559 PlaylistWindow::DurationListener::_HandleItemRemoved(int32 index) 560 { 561 bigtime_t* deleted = fKnown.RemoveItemAt(index); 562 fTotalDuration -= *deleted; 563 fParent._UpdateTotalDuration(fTotalDuration); 564 565 delete deleted; 566 } 567 568 569 bigtime_t 570 PlaylistWindow::DurationListener::_DetermineItemDuration(PlaylistItem* item) 571 { 572 bigtime_t duration; 573 if (item->GetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration) == B_OK) 574 return duration; 575 576 // We have to find out the duration ourselves 577 if (FilePlaylistItem* file = dynamic_cast<FilePlaylistItem*>(item)) { 578 // We are dealing with a file 579 BMediaFile mediaFile(&file->Ref()); 580 581 if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() < 1) 582 return 0; 583 584 duration = mediaFile.TrackAt(0)->Duration(); 585 } else { 586 // Not a file, so fall back to the generic TrackSupplier solution 587 TrackSupplier* supplier = item->CreateTrackSupplier(); 588 589 AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0); 590 VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0); 591 592 duration = max_c(au == NULL ? 0 : au->Duration(), 593 vi == NULL ? 0 : vi->Duration()); 594 595 delete vi; 596 delete au; 597 delete supplier; 598 } 599 600 // Store the duration for later use 601 item->SetAttribute(PlaylistItem::ATTR_INT64_DURATION, duration); 602 603 return duration; 604 } 605 -
src/apps/mediaplayer/playlist/PlaylistWindow.h
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.h b/src/apps/mediaplayer/playlist/PlaylistWindow.h index 2372385..6b70e76 100644
a b 11 11 12 12 13 13 #include <Entry.h> 14 #include <ObjectList.h> 14 15 #include <Window.h> 15 16 17 #include "PlaylistObserver.h" 16 18 #include "ListenerAdapter.h" 17 19 18 20 … … class BMenuItem; 21 23 class CommandStack; 22 24 class Controller; 23 25 class Notifier; 24 class Playlist;25 26 class PlaylistListView; 26 27 class RWLocker; 27 28 class BButton; 28 29 class BFilePanel; 30 class BStringView; 29 31 30 32 31 33 enum { … … public: 53 55 virtual void MessageReceived(BMessage* message); 54 56 55 57 private: 58 59 class DurationListener : public PlaylistObserver, public BLooper { 60 public: 61 62 DurationListener(PlaylistWindow& parent); 63 ~DurationListener(); 64 65 void MessageReceived(BMessage* message); 66 67 bigtime_t TotalDuration(); 68 69 private: 70 void _HandleItemAdded(PlaylistItem* item, 71 int32 index); 72 void _HandleItemRemoved(int32 index); 73 bigtime_t _DetermineItemDuration(PlaylistItem* item); 74 75 BObjectList<bigtime_t> 76 fKnown; 77 bigtime_t fTotalDuration; 78 PlaylistWindow& fParent; 79 }; 80 81 friend class DurationListener; 82 56 83 void _CreateMenu(BRect& frame); 57 84 void _ObjectChanged(const Notifier* object); 58 85 void _SavePlaylist(const BMessage* filePanelMessage); 59 86 void _SavePlaylist(const entry_ref& ref); 60 87 void _SavePlaylist(BEntry& origEntry, 61 88 BEntry& tempEntry, const char* finalName); 89 void _QueryInitialDurations(); 90 void _UpdateTotalDuration(bigtime_t duration); 62 91 63 92 Playlist* fPlaylist; 64 93 PlaylistListView* fListView; … … private: 72 101 ListenerAdapter fCommandStackListener; 73 102 74 103 entry_ref fSavedPlaylistRef; 104 105 DurationListener* fDurationListener; 106 BStringView* fTotalDuration; 75 107 }; 76 108 77 109