Commit 6e14a79e authored by Carola Nitz's avatar Carola Nitz

added useractivitys to restart mediaplayback from corespotlight

parent 77e465f3
......@@ -45,7 +45,7 @@
#import "VLCNavigationController.h"
#import "VLCSidebarController.h"
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[UIDevice currentDevice] systemVersion].floatValue >= [v floatValue])
#define SYSTEM_RUNS_IOS8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
......
......@@ -184,9 +184,9 @@ NSString *const VLCDropboxSessionWasAuthorized = @"VLCDropboxSessionWasAuthorize
- (BOOL)application:(UIApplication *)application willContinueUserActivityWithType:(NSString *)userActivityType
{
if ([userActivityType isEqualToString:@"org.videolan.vlc-ios.librarymode"] ||
[userActivityType isEqualToString:@"org.videolan.vlc-ios.playing"] ||
[userActivityType isEqualToString:@"org.videolan.vlc-ios.libraryselection"])
if ([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
[userActivityType isEqualToString:kVLCUserActivityPlaying] ||
[userActivityType isEqualToString:kVLCUserActivityLibrarySelection])
return YES;
return NO;
......@@ -197,21 +197,30 @@ continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *))restorationHandler
{
NSString *userActivityType = userActivity.activityType;
NSDictionary *dict = userActivity.userInfo;
if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
[userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
if([userActivityType isEqualToString:@"org.videolan.vlc-ios.librarymode"] ||
[userActivityType isEqualToString:@"org.videolan.vlc-ios.libraryselection"]) {
NSDictionary *dict = userActivity.userInfo;
VLCLibraryMode libraryMode = (VLCLibraryMode)[(NSNumber *)dict[@"state"] integerValue];
if (libraryMode <= VLCLibraryModeAllSeries) {
[[VLCSidebarController sharedInstance] selectRowAtIndexPath:[NSIndexPath indexPathForRow:libraryMode inSection:0]
scrollPosition:UITableViewScrollPositionTop];
[self.libraryViewController setLibraryMode:(VLCLibraryMode)libraryMode];
[self.libraryViewController setLibraryMode:libraryMode];
}
[self.libraryViewController restoreUserActivityState:userActivity];
_isComingFromHandoff = YES;
return YES;
} else {
NSURL *uriRepresentation = dict[@"playingmedia"];
NSManagedObject *managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
if (managedObject == nil) {
APLog(@"%s file not found: %@",__PRETTY_FUNCTION__,userActivity);
return NO;
}
[[VLCPlaybackController sharedInstance] openMediaLibraryObject:managedObject];
return YES;
}
return NO;
}
......@@ -422,7 +431,7 @@ didFailToContinueUserActivityWithType:(NSString *)userActivityType
[[VLCPlaybackController sharedInstance] remoteControlReceivedWithEvent:event];
}
#pragma mark - watch struff
#pragma mark - watch stuff
- (void)application:(UIApplication *)application
handleWatchKitExtensionRequest:(NSDictionary *)userInfo
reply:(void (^)(NSDictionary *))reply
......@@ -478,7 +487,7 @@ handleWatchKitExtensionRequest:(NSDictionary *)userInfo
NSNumber *volume = (id)message.payload;
if ([volume isKindOfClass:[NSNumber class]]) {
/*
* Since WatchKit doen't provide something like MPVolumeView we use deprecated API.
* Since WatchKit doesn't provide something like MPVolumeView we use deprecated API.
* rdar://20783803 Feature Request: WatchKit equivalent for MPVolumeView
*/
[MPMusicPlayerController applicationMusicPlayer].volume = volume.floatValue;
......
......@@ -80,6 +80,10 @@
#define kVLCStoredServerList @"kVLCStoredServerList"
#define kVLCUserActivityPlaying @"org.videolan.vlc-ios.playing"
#define kVLCUserActivityLibrarySelection @"org.videolan.vlc-ios.libraryselection"
#define kVLCUserActivityLibraryMode @"org.videolan.vlc-ios.librarymode"
/* LEGACY KEYS, DO NOT USE IN NEW CODE */
#define kVLCFTPServer @"ftp-server"
#define kVLCFTPLogin @"ftp-login"
......
......@@ -306,7 +306,7 @@
album.name,
(unsigned long)albumTracks.count]];
for (MLAlbumTrack *track in albumTracks) {
MLFile *anyFileFromTrack = (MLFile *)[[track files] anyObject];
MLFile *anyFileFromTrack = [track anyFileFromTrack];
duration = [[VLCTime timeWithNumber:[anyFileFromTrack duration]] stringValue];
[mediaInHtml addObject:[NSString stringWithFormat:
@"<div style=\"background-image:url('thumbnail/%@.png')\"> \
......
......@@ -29,6 +29,7 @@
#import "VLCPlaybackController+MediaLibrary.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import <CoreSpotlight/CoreSpotlight.h>
/* prefs keys */
static NSString *kDisplayedFirstSteps = @"Did we display the first steps tutorial?";
......@@ -299,6 +300,30 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
} else {
VLCPlaybackController *vpc = [VLCPlaybackController sharedInstance];
[vpc playMediaLibraryObject:mediaObject];
[self createSpotlightItem:mediaObject];
}
}
- (void)createSpotlightItem:(nonnull NSManagedObject *)mediaObject
{
if ([CSSearchableItemAttributeSet class] != nil && [(VLCAppDelegate *)[UIApplication sharedApplication].delegate passcodeValidated]) {
self.userActivity = [[NSUserActivity alloc] initWithActivityType:kVLCUserActivityPlaying];
self.userActivity.title = ((MLFile *)mediaObject).title;
self.userActivity.userInfo = @{@"playingmedia":mediaObject.objectID.URIRepresentation};
if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
MLFile *file = [(MLAlbumTrack *)mediaObject anyFileFromTrack];
self.userActivity.contentAttributeSet = file.coreSpotlightAttributeSet;
} else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) {
MLFile *file = [(MLShowEpisode *)mediaObject anyFileFromEpisode];
self.userActivity.contentAttributeSet = file.coreSpotlightAttributeSet;
} else {
self.userActivity.contentAttributeSet = ((MLFile *)mediaObject).coreSpotlightAttributeSet;
}
self.userActivity.eligibleForSearch = YES;
self.userActivity.eligibleForHandoff = YES;
//self.userActivity.contentUserAction = NSUserActivityContentUserActionPlay;
[self.userActivity becomeCurrent];
}
}
......@@ -1362,9 +1387,9 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
if ([mediaItem isKindOfClass:[MLFile class]])
fileURL = [(MLFile *) mediaItem url];
else if ([mediaItem isKindOfClass:[MLAlbumTrack class]])
fileURL = [(MLFile *) [[(MLAlbumTrack *) mediaItem files] anyObject] url];
fileURL = [[(MLAlbumTrack *) mediaItem anyFileFromTrack] url];
else if ([mediaItem isKindOfClass:[MLShowEpisode class]])
fileURL = [(MLFile *) [[(MLShowEpisode *) mediaItem files] anyObject] url];
fileURL = [[(MLShowEpisode *) mediaItem anyFileFromEpisode] url];
if ([fileURL isFileURL])
[fileURLobjects addObject:fileURL];
......@@ -1679,8 +1704,8 @@ static NSString *kUsingTableViewToShowData = @"UsingTableViewToShowData";
- (void)restoreUserActivityState:(NSUserActivity *)activity
{
NSString *userActivityType = activity.activityType;
if([userActivityType isEqualToString:@"org.videolan.vlc-ios.librarymode"] ||
[userActivityType isEqualToString:@"org.videolan.vlc-ios.libraryselection"]) {
if([userActivityType isEqualToString:kVLCUserActivityLibraryMode] ||
[userActivityType isEqualToString:kVLCUserActivityLibrarySelection]) {
NSDictionary *dict = activity.userInfo;
NSString *folderPath = dict[@"folder"];
......
......@@ -14,4 +14,5 @@
@class NSManagedObject;
@interface VLCPlaybackController (MediaLibrary)
- (void)playMediaLibraryObject:(NSManagedObject *)mediaObject;
- (void)openMediaLibraryObject:(NSManagedObject *)mediaObject;
@end
......@@ -15,6 +15,13 @@
@implementation VLCPlaybackController (MediaLibrary)
/*
Open a file in the libraryViewController and toggle the playstate
@param mediaObject the object that should be openend
*/
- (void)playMediaLibraryObject:(NSManagedObject *)mediaObject
{
self.fullscreenSessionRequested = YES;
......@@ -37,6 +44,38 @@
}
}
/*
Open a file in the libraryViewController without changing the playstate
@param mediaObject the object that should be openend
*/
- (void)openMediaLibraryObject:(NSManagedObject *)mediaObject
{
if (self.activePlaybackSession) {
NSArray *files = [MLFile fileForURL:self.mediaPlayer.media.url];
MLFile *nowPlayingFile = (MLFile *)(NSManagedObject *)files.firstObject;
MLFile *newFile;
if ([mediaObject isKindOfClass:[MLAlbumTrack class]]) {
newFile = ((MLAlbumTrack *)mediaObject).anyFileFromTrack;
} else if ([mediaObject isKindOfClass:[MLShowEpisode class]]) {
newFile = ((MLShowEpisode *)mediaObject).anyFileFromEpisode;
} else if ([mediaObject isKindOfClass:[MLFile class]]) {
newFile = (MLFile *)mediaObject;
}
//if the newfile is not the currently playing one, stop and start the new one else do nothing
if (![nowPlayingFile isEqual:newFile]) {
[self stopPlayback];
[self playMediaLibraryObject:mediaObject];
}
return;
}
//if nothing is playing start playing
[self playMediaLibraryObject:mediaObject];
}
- (void)configureWithFile:(MLFile *)file
{
if (file.labels.count == 0) {
......@@ -67,7 +106,7 @@
NSArray *tracks = [[albumTrack album] sortedTracks];
NSMutableArray *files = [NSMutableArray arrayWithCapacity:tracks.count];
for (MLAlbumTrack *track in tracks) {
MLFile *file = track.files.anyObject;
MLFile *file = track.anyFileFromTrack;
if (file)
[files addObject:file];
}
......
......@@ -110,7 +110,7 @@
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
if (anyFileFromTrack)
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
......@@ -154,7 +154,7 @@
[_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
if (anyFileFromTrack)
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
......@@ -239,7 +239,7 @@
- (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
{
MLFile *anyFileFromTrack = albumTrack.files.anyObject;
MLFile *anyFileFromTrack = albumTrack.anyFileFromTrack;
self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
self.titleLabel.text = albumTrack.title;
......@@ -351,7 +351,7 @@
else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];
theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
if (!theFile) {
self.metaDataLabel.hidden = YES;
......
......@@ -76,7 +76,7 @@
[_mediaObject removeObserver:self forKeyPath:@"artist"];
[_mediaObject removeObserver:self forKeyPath:@"title"];
[_mediaObject removeObserver:self forKeyPath:@"files"];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
if (anyFileFromTrack)
[anyFileFromTrack removeObserver:self forKeyPath:@"artworkURL"];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
......@@ -120,7 +120,7 @@
[_mediaObject addObserver:self forKeyPath:@"artist" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"title" options:0 context:nil];
[_mediaObject addObserver:self forKeyPath:@"files" options:0 context:nil];
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject files].anyObject;
MLFile *anyFileFromTrack = [(MLAlbumTrack *)_mediaObject anyFileFromTrack];
if (anyFileFromTrack)
[anyFileFromTrack addObserver:self forKeyPath:@"artworkURL" options:0 context:nil];
} else if ([_mediaObject isKindOfClass:[MLFile class]]) {
......@@ -228,7 +228,7 @@
- (void)_configureForAlbumTrack:(MLAlbumTrack *)albumTrack
{
MLFile *anyFileFromTrack = albumTrack.files.anyObject;
MLFile *anyFileFromTrack = albumTrack.anyFileFromTrack;
self.subtitleLabel.text = [NSString stringWithFormat:@"%@ — %@ — %@", albumTrack.artist, [NSString stringWithFormat:NSLocalizedString(@"LIBRARY_TRACK_N", nil), albumTrack.trackNumber.intValue], [VLCTime timeWithNumber:[anyFileFromTrack duration]]];
self.titleLabel.text = albumTrack.title;
[self _showPositionOfItem:anyFileFromTrack];
......@@ -337,9 +337,9 @@
if ([self.mediaObject isKindOfClass:[MLFile class]])
theFile = (MLFile *)self.mediaObject;
else if ([self.mediaObject isKindOfClass:[MLShowEpisode class]])
theFile = [[(MLShowEpisode *)self.mediaObject files]anyObject];
theFile = [(MLShowEpisode *)self.mediaObject anyFileFromEpisode];
else if ([self.mediaObject isKindOfClass:[MLAlbumTrack class]])
theFile = [[(MLAlbumTrack *)self.mediaObject files]anyObject];
theFile = [(MLAlbumTrack *)self.mediaObject anyFileFromTrack];
NSMutableString *mediaInfo = [[NSMutableString alloc] init];
......
......@@ -246,7 +246,7 @@
{
__block MLFile *anyFileFromAnyTrack = nil;
void (^getFileBlock)(void) = ^(){
anyFileFromAnyTrack = [albumTrack files].anyObject;
anyFileFromAnyTrack = [albumTrack anyFileFromTrack];
};
if ([NSThread isMainThread])
getFileBlock();
......
......@@ -37,6 +37,7 @@
#import "MLShowEpisode.h"
#import "MLAlbum.h"
#import "MLAlbumTrack.h"
#import "VLCConstants.h"
#ifndef NDEBUG
#define APLog(format, ...) NSLog(format, ## __VA_ARGS__)
......
......@@ -15,6 +15,7 @@
#import "VLCThumbnailsCache.h"
#import "WKInterfaceObject+VLCProgress.h"
#import "VLCWatchMessage.h"
#import "VLCConstants.h"
@interface VLCDetailInterfaceController ()
@property (nonatomic, weak) NSManagedObject *managedObject;
......@@ -84,7 +85,7 @@
id payload = self.managedObject.objectID.URIRepresentation.absoluteString;
NSDictionary *dict = [VLCWatchMessage messageDictionaryForName:@"playFile"
payload:payload];
[self updateUserActivity:@"org.videolan.vlc-ios.playing" userInfo:@{@"playingmedia":self.managedObject.objectID.URIRepresentation} webpageURL:nil];
[self updateUserActivity:kVLCUserActivityPlaying userInfo:@{@"playingmedia":self.managedObject.objectID.URIRepresentation} webpageURL:nil];
[WKInterfaceController openParentApplication:dict reply:^(NSDictionary *replyInfo, NSError *error) {
[self showNowPlaying:nil];
......
......@@ -87,7 +87,7 @@ static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.db
@"folder" : folderRepresentation};
[self invalidateUserActivity];
[self updateUserActivity:@"org.videolan.vlc-ios.libraryselection"
[self updateUserActivity:kVLCUserActivityLibrarySelection
userInfo:userDict
webpageURL:nil];
} else {
......@@ -142,7 +142,7 @@ static NSString *const VLCDBUpdateNotificationRemote = @"org.videolan.ios-app.db
{
//should also handle diving into a folder
[self invalidateUserActivity];
[self updateUserActivity:@"org.videolan.vlc-ios.librarymode" userInfo:@{@"state" : @(libraryMode)} webpageURL:nil];
[self updateUserActivity:kVLCUserActivityLibraryMode userInfo:@{@"state" : @(libraryMode)} webpageURL:nil];
_libraryMode = libraryMode;
}
......
......@@ -2325,6 +2325,7 @@
"$(SRCROOT)/ImportedSources/MediaLibraryKit/Headers/Public",
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/Sources",
);
INFOPLIST_FILE = "VLC for iOS WatchKit Extension/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
......@@ -2369,6 +2370,7 @@
"$(SRCROOT)/ImportedSources/MediaLibraryKit/Headers/Public",
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/Sources",
);
INFOPLIST_FILE = "VLC for iOS WatchKit Extension/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
......@@ -2413,6 +2415,7 @@
"$(SRCROOT)/ImportedSources/MediaLibraryKit/Headers/Public",
"$(inherited)",
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/Sources",
);
INFOPLIST_FILE = "VLC for iOS WatchKit Extension/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 8.2;
......
......@@ -12,12 +12,22 @@
"filename" : "AppIcon29x29@2x-1.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "AppIcon40x40@2x-1.png",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"size" : "57x57",
"idiom" : "iphone",
......@@ -105,16 +115,16 @@
{
"size" : "24x24",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon24@2x.png",
"scale" : "2x",
"role" : "notificationCenter",
"subtype" : "38mm"
},
{
"size" : "27.5x27.5",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon27.5@2x.png",
"scale" : "2x",
"role" : "notificationCenter",
"subtype" : "42mm"
},
......@@ -135,32 +145,32 @@
{
"size" : "40x40",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon40@2x.png",
"scale" : "2x",
"role" : "appLauncher",
"subtype" : "38mm"
},
{
"size" : "44x44",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon44@2x.png",
"scale" : "2x",
"role" : "longLook",
"subtype" : "42mm"
},
{
"size" : "86x86",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon86@2x.png",
"scale" : "2x",
"role" : "quickLook",
"subtype" : "38mm"
},
{
"size" : "98x98",
"idiom" : "watch",
"scale" : "2x",
"filename" : "AppIcon98@2x.png",
"scale" : "2x",
"role" : "quickLook",
"subtype" : "42mm"
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment