Ticket #6564: mediaplayer.patch
File mediaplayer.patch, 8.9 KB (added by , 8 years ago) |
---|
-
src/apps/mediaplayer/Controller.cpp
From d7a26102209b6cbc19bc09d98b4b67464f4cee1f 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/PlaylistWindow.cpp
-- 2.2.2 From 433d5e42b9ed6080fd81cc892483b0f34da64a38 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/PlaylistWindow.cpp | 179 ++++++++++++++++++++++- src/apps/mediaplayer/playlist/PlaylistWindow.h | 34 ++++- 2 files changed, 209 insertions(+), 4 deletions(-) diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.cpp b/src/apps/mediaplayer/playlist/PlaylistWindow.cpp index 08ce627..faedf92 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(*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 fDuration = new BStringView(frame, "fDuration", "", 122 B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); 123 AddChild(fDuration); 124 125 _UpdateDuration(0); 126 127 { 128 BAutolock _(fPlaylist); 129 130 _GetInitialDuration(); 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); 124 150 } 125 151 126 152 … … PlaylistWindow::_SavePlaylist(BEntry& origEntry, BEntry& tempEntry, 422 448 info.SetType("application/x-vnd.haiku-playlist"); 423 449 } 424 450 451 452 void 453 PlaylistWindow::_GetInitialDuration() 454 { 455 BAutolock lock(fPlaylist); 456 457 for (int32 i = 0; i < fPlaylist->CountItems(); i++) { 458 BMessage addMessage(MSG_PLAYLIST_ITEM_ADDED); 459 addMessage.AddPointer("item", fPlaylist->ItemAt(i)); 460 addMessage.AddInt32("index", i); 461 462 BMessenger(&fDurationListener).SendMessage(&addMessage); 463 } 464 } 465 466 467 void 468 PlaylistWindow::_UpdateDuration(bigtime_t duration) 469 { 470 BAutolock lock(this); 471 472 BString text; 473 474 char buffer[64]; 475 duration /= 1000000; 476 duration_to_string(duration, buffer, sizeof(buffer)); 477 478 text << B_TRANSLATE("Total duration:") << " " << buffer; 479 480 fDuration->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 fDuration(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 if (message->FindPointer("item", &item) == B_OK 513 && message->FindInt32("index", &index) == B_OK) { 514 _HandleItemAdded(static_cast<PlaylistItem*>(item), index); 515 } 516 517 break; 518 } 519 520 case MSG_PLAYLIST_ITEM_REMOVED: 521 { 522 int32 index; 523 524 if (message->FindInt32("index", &index) == B_OK) { 525 _HandleItemRemoved(index); 526 } 527 528 break; 529 } 530 531 default: 532 BLooper::MessageReceived(message); 533 break; 534 } 535 } 536 537 538 bigtime_t 539 PlaylistWindow::DurationListener::Duration() 540 { 541 return fDuration; 542 } 543 544 545 void 546 PlaylistWindow::DurationListener::_HandleItemAdded(PlaylistItem* item, 547 int32 index) 548 { 549 bigtime_t duration = _DetermineDuration(item); 550 fDuration += duration; 551 fParent._UpdateDuration(fDuration); 552 fKnown.AddItem(new bigtime_t(duration), index); 553 } 554 555 556 void 557 PlaylistWindow::DurationListener::_HandleItemRemoved(int32 index) 558 { 559 bigtime_t* deleted = fKnown.RemoveItemAt(index); 560 fDuration -= *deleted; 561 fParent._UpdateDuration(fDuration); 562 563 delete deleted; 564 } 565 566 567 bigtime_t 568 PlaylistWindow::DurationListener::_DetermineDuration(PlaylistItem* item) 569 { 570 // TODO: Save track duration to an attributee 571 if (FilePlaylistItem* file = dynamic_cast<FilePlaylistItem*>(item)) { 572 // We are dealing with a file 573 BMediaFile mediaFile(&file->Ref()); 574 575 if (mediaFile.InitCheck() != B_OK || mediaFile.CountTracks() < 1) 576 return 0; 577 578 return mediaFile.TrackAt(0)->Duration(); 579 } else { 580 // Not a file, so fall back to the generic TrackSupplier solution 581 582 TrackSupplier* supplier = item->CreateTrackSupplier(); 583 584 AudioTrackSupplier* au = supplier->CreateAudioTrackForIndex(0); 585 VideoTrackSupplier* vi = supplier->CreateVideoTrackForIndex(0); 586 587 bigtime_t duration = max_c(au == NULL ? 0 : au->Duration(), 588 vi == NULL ? 0 : vi->Duration()); 589 590 delete vi; 591 delete au; 592 delete supplier; 593 594 return duration; 595 } 596 } 597 -
src/apps/mediaplayer/playlist/PlaylistWindow.h
diff --git a/src/apps/mediaplayer/playlist/PlaylistWindow.h b/src/apps/mediaplayer/playlist/PlaylistWindow.h index 2372385..9d799e2 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 Duration(); 68 69 private: 70 void _HandleItemAdded(PlaylistItem* item, 71 int32 index); 72 void _HandleItemRemoved(int32 index); 73 bigtime_t _DetermineDuration(PlaylistItem* item); 74 75 BObjectList<bigtime_t> 76 fKnown; 77 bigtime_t fDuration; 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 _GetInitialDuration(); 90 void _UpdateDuration(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* fDuration; 75 107 }; 76 108 77 109