[vlc-commits] macosx: handle execution without media library gracefully
Felix Paul Kühne
git at videolan.org
Mon Jul 15 13:58:29 CEST 2019
vlc | branch: master | Felix Paul Kühne <felix at feepk.net> | Sun Jul 14 17:35:51 2019 +0200| [86ddf1505501cde66ac02892c468b430048382b7] | committer: Felix Paul Kühne
macosx: handle execution without media library gracefully
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=86ddf1505501cde66ac02892c468b430048382b7
---
modules/gui/macosx/library/VLCLibraryController.h | 2 +-
modules/gui/macosx/library/VLCLibraryController.m | 36 ++++++++++++++++++++--
.../gui/macosx/library/VLCLibraryVideoDataSource.m | 3 ++
.../macosx/preferences/VLCSimplePrefsController.m | 6 +++-
4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/modules/gui/macosx/library/VLCLibraryController.h b/modules/gui/macosx/library/VLCLibraryController.h
index 0c16554b1c..271112cad1 100644
--- a/modules/gui/macosx/library/VLCLibraryController.h
+++ b/modules/gui/macosx/library/VLCLibraryController.h
@@ -31,7 +31,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface VLCLibraryController : NSObject
- at property (readonly) VLCLibraryModel *libraryModel;
+ at property (readonly, nullable) VLCLibraryModel *libraryModel;
- (int)appendItemToPlaylist:(VLCMediaLibraryMediaItem *)mediaItem playImmediately:(BOOL)playImmediately;
- (void)showItemInFinder:(VLCMediaLibraryMediaItem *)mediaItem;
diff --git a/modules/gui/macosx/library/VLCLibraryController.m b/modules/gui/macosx/library/VLCLibraryController.m
index 2a2194b670..3477166a47 100644
--- a/modules/gui/macosx/library/VLCLibraryController.m
+++ b/modules/gui/macosx/library/VLCLibraryController.m
@@ -47,6 +47,10 @@ float kVLCDefaultThumbnailPosition = .15;
self = [super init];
if (self) {
_p_libraryInstance = vlc_ml_instance_get(getIntf());
+ if (!_p_libraryInstance) {
+ msg_Info(getIntf(), "VLC runs without media library support");
+ return self;
+ }
_libraryModel = [[VLCLibraryModel alloc] initWithLibrary:_p_libraryInstance];
_unsorted = YES;
@@ -83,16 +87,23 @@ float kVLCDefaultThumbnailPosition = .15;
- (void)applicationWillEnterBackground:(NSNotification *)aNotification
{
- vlc_ml_resume_background(_p_libraryInstance);
+ if (_p_libraryInstance) {
+ vlc_ml_resume_background(_p_libraryInstance);
+ }
}
- (void)applicationWillBecomeActive:(NSNotification *)aNotification
{
- vlc_ml_pause_background(_p_libraryInstance);
+ if (_p_libraryInstance) {
+ vlc_ml_pause_background(_p_libraryInstance);
+ }
}
- (void)playbackStateChanged:(NSNotification *)aNotification
{
+ if (!_p_libraryInstance) {
+ return;
+ }
VLCPlayerController *playerController = aNotification.object;
if (playerController.playerState == VLC_PLAYER_STATE_PLAYING) {
vlc_ml_pause_background(_p_libraryInstance);
@@ -103,6 +114,9 @@ float kVLCDefaultThumbnailPosition = .15;
- (int)appendItemToPlaylist:(VLCMediaLibraryMediaItem *)mediaItem playImmediately:(BOOL)playImmediately
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
input_item_t *p_inputItem = vlc_ml_get_input_item(_p_libraryInstance, mediaItem.libraryID);
int ret = [[[VLCMain sharedInstance] playlistController] addInputItem:p_inputItem atPosition:-1 startPlayback:playImmediately];
input_item_Release(p_inputItem);
@@ -129,6 +143,9 @@ float kVLCDefaultThumbnailPosition = .15;
- (int)attemptToGenerateThumbnailForMediaItem:(VLCMediaLibraryMediaItem *)mediaItem
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_media_generate_thumbnail(_p_libraryInstance,
mediaItem.libraryID,
VLC_ML_THUMBNAIL_SMALL,
@@ -141,26 +158,41 @@ float kVLCDefaultThumbnailPosition = .15;
- (int)addFolderWithFileURL:(NSURL *)fileURL
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_add_folder(_p_libraryInstance, [[fileURL absoluteString] UTF8String]);
}
- (int)banFolderWithFileURL:(NSURL *)fileURL
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_ban_folder(_p_libraryInstance, [[fileURL absoluteString] UTF8String]);
}
- (int)unbanFolderWithFileURL:(NSURL *)fileURL
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_unban_folder(_p_libraryInstance, [[fileURL absoluteString] UTF8String]);
}
- (int)removeFolderWithFileURL:(NSURL *)fileURL
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_remove_folder(_p_libraryInstance, [[fileURL absoluteString] UTF8String]);
}
- (int)clearHistory
{
+ if (!_p_libraryInstance) {
+ return VLC_ENOOBJ;
+ }
return vlc_ml_clear_history(_p_libraryInstance);
}
diff --git a/modules/gui/macosx/library/VLCLibraryVideoDataSource.m b/modules/gui/macosx/library/VLCLibraryVideoDataSource.m
index 7217ff962e..de91928fa7 100644
--- a/modules/gui/macosx/library/VLCLibraryVideoDataSource.m
+++ b/modules/gui/macosx/library/VLCLibraryVideoDataSource.m
@@ -35,6 +35,9 @@
- (NSInteger)collectionView:(NSCollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
+ if (!_libraryModel) {
+ return 0;
+ }
if (collectionView == self.recentMediaCollectionView) {
return [_libraryModel numberOfRecentMedia];
}
diff --git a/modules/gui/macosx/preferences/VLCSimplePrefsController.m b/modules/gui/macosx/preferences/VLCSimplePrefsController.m
index 66c29ec665..6668940a59 100644
--- a/modules/gui/macosx/preferences/VLCSimplePrefsController.m
+++ b/modules/gui/macosx/preferences/VLCSimplePrefsController.m
@@ -1596,8 +1596,12 @@ static inline void save_string_list(intf_thread_t * p_intf, id object, const cha
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
+ VLCLibraryModel *libraryModel = [_libraryController libraryModel];
+ if (!libraryModel) {
+ return 0;
+ }
if (!_cachedFolderList) {
- _cachedFolderList = [[_libraryController libraryModel] listOfMonitoredFolders];
+ _cachedFolderList = [libraryModel listOfMonitoredFolders];
}
return _cachedFolderList.count;
}
More information about the vlc-commits
mailing list