Commit 86219643 authored by Tobias's avatar Tobias Committed by Felix Paul Kühne

use mediaLibraryObject for now playing info

parent d49ef114
......@@ -146,7 +146,7 @@
[[VLCNotificationRelay sharedRelay] addRelayLocalName:NSManagedObjectContextDidSaveNotification toRemoteName:@"org.videolan.ios-app.dbupdate"];
[[VLCNotificationRelay sharedRelay] addRelayLocalName:@"nowPlayingInfoUpdate" toRemoteName:@"org.videolan.ios-app.nowPlayingInfoUpdate"];
[[VLCNotificationRelay sharedRelay] addRelayLocalName:kVLCNotificationNowPlayingInfoUpdate toRemoteName:kVLCDarwinNotificationNowPlayingInfoUpdate];
return YES;
}
......@@ -570,7 +570,7 @@
- (void)application:(UIApplication *)application handleWatchKitExtensionRequest:(NSDictionary *)userInfo reply:(void (^)(NSDictionary *))reply {
NSDictionary *reponseDict = nil;
if ([userInfo[@"name"] isEqualToString:@"getNowPlayingInfo"]) {
reponseDict = [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo;
reponseDict = [self nowPlayingResponseDict];
} else if ([userInfo[@"name"] isEqualToString:@"playpause"]) {
[_movieViewController playPause];
} else if ([userInfo[@"name"] isEqualToString:@"skipForward"]) {
......@@ -584,19 +584,32 @@
}
reply(reponseDict);
}
- (void)playFileFromWatch:(NSDictionary *)userInfo {
MLMediaLibrary *library = [MLMediaLibrary sharedMediaLibrary];
NSManagedObject *managedObject = nil;
NSString *uriString = userInfo[@"URIRepresentation"];
NSURL *uriRepresentation = [NSURL URLWithString:uriString];
NSPersistentStoreCoordinator *persistentStoreCoordinator = library.persistentStoreCoordinator;
if (persistentStoreCoordinator) {
NSManagedObjectID *objectID = [persistentStoreCoordinator managedObjectIDForURIRepresentation:uriRepresentation];
NSManagedObjectContext *moc = [(id)library managedObjectContext];
if (moc) {
NSManagedObject *managedObject = [moc objectWithID:objectID];
[self openMediaFromManagedObject:managedObject];
}
if (uriString) {
NSURL *uriRepresentation = [NSURL URLWithString:uriString];
managedObject = [[MLMediaLibrary sharedMediaLibrary] objectForURIRepresentation:uriRepresentation];
}
if (managedObject) {
[self openMediaFromManagedObject:managedObject];
}
}
- (NSDictionary *)nowPlayingResponseDict {
NSMutableDictionary *response = [NSMutableDictionary new];
NSDictionary *nowPlayingInfo = [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo;
if (nowPlayingInfo) {
response[@"nowPlayingInfo"] = nowPlayingInfo;
}
MLFile *currentFile = _movieViewController.currentlyPlayingMediaFile;
NSString *URIString = currentFile.objectID.URIRepresentation.absoluteString;
if (URIString) {
response[@"URIRepresentation"] = URIString;
}
return response;
}
@end
......@@ -77,6 +77,10 @@
#define kBlobHash @"521923d214b9ae628da7987cf621e94c4afdd726"
#define kVLCNotificationNowPlayingInfoUpdate @"nowPlayingInfoUpdate"
#define kVLCDarwinNotificationNowPlayingInfoUpdate @"org.videolan.ios-app.nowPlayingInfoUpdate"
#if TARGET_IPHONE_SIMULATOR
#define WifiInterfaceName @"en1"
#else
......
......@@ -92,6 +92,9 @@
@property (nonatomic, retain) VLCMediaList *mediaList;
@property (nonatomic, readwrite) int itemInMediaListToBePlayedFirst;
/* returns nil if currenlty plaing item is not a MLFile, e.g. a url */
@property (nonatomic, strong, readonly) MLFile *currentlyPlayingMediaFile;
- (IBAction)closePlayback:(id)sender;
- (void)unanimatedPlaybackStop;
......
......@@ -179,6 +179,20 @@ typedef NS_ENUM(NSInteger, VLCPanType) {
[self _startPlayback];
}
- (MLFile *)currentlyPlayingMediaFile {
MLFile *mediaFile = self.fileFromMediaLibrary;
if (mediaFile) {
return mediaFile;
}
// VLCMediaList *mediaList = self.mediaList;
// if (mediaList) {
// TODO: get current MLFile ?
// }
return nil;
}
- (void)viewDidLoad
{
[super viewDidLoad];
......@@ -2326,7 +2340,7 @@ static inline NSArray * RemoteCommandCenterCommandsToHandle(MPRemoteCommandCente
}
[MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = currentlyPlayingTrackInfo;
[[NSNotificationCenter defaultCenter] postNotificationName:@"nowPlayingInfoUpdate" object:self];
[[NSNotificationCenter defaultCenter] postNotificationName:kVLCNotificationNowPlayingInfoUpdate object:self];
}
#pragma mark - autorotation
......
......@@ -135,9 +135,11 @@
</button>
</items>
</group>
<imageView width="1" alignment="center" contentMode="scaleAspectFill" id="3JI-SS-2Wb"/>
</items>
<connections>
<outlet property="durationLabel" destination="D0h-cq-wsv" id="3AN-YZ-yEj"/>
<outlet property="image" destination="3JI-SS-2Wb" id="rqC-Lb-tRt"/>
<outlet property="playPauseButton" destination="BAZ-aC-ETt" id="X17-bz-cFy"/>
<outlet property="titleLabel" destination="H58-Y8-Tbc" id="xZs-ZW-Shj"/>
</connections>
......
......@@ -14,6 +14,7 @@
#import <Foundation/Foundation.h>
@interface VLCNowPlayingInterfaceController : WKInterfaceController
@property (weak, nonatomic) IBOutlet WKInterfaceImage *image;
@property (weak, nonatomic) IBOutlet WKInterfaceLabel *titleLabel;
@property (weak, nonatomic) IBOutlet WKInterfaceLabel *durationLabel;
@property (weak, nonatomic) IBOutlet WKInterfaceButton *playPauseButton;
......
......@@ -13,7 +13,9 @@
#import "VLCNowPlayingInterfaceController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <MobileVLCKit/VLCTime.h>
#import <MediaLibraryKit/MediaLibraryKit.h>
#import "VLCNotificationRelay.h"
#import "VLCThumbnailsCache.h"
@interface VLCNowPlayingInterfaceController ()
@property (nonatomic, copy) NSString *titleString;
......@@ -56,13 +58,25 @@
- (void)requestNowPlayingInfo {
[WKInterfaceController openParentApplication:@{@"name": @"getNowPlayingInfo"} reply:^(NSDictionary *replyInfo, NSError *error) {
[self updateWithNowPlayingInfo:replyInfo];
NSLog(@"nowplayingInfo: %@",replyInfo);
MLFile *file = nil;
NSString *uriString = replyInfo[@"URIRepresentation"];
if (uriString) {
NSURL *uriRepresentation = [NSURL URLWithString:uriString];
file = [MLFile fileForURIRepresentation:uriRepresentation];
}
[self updateWithNowPlayingInfo:replyInfo[@"nowPlayingInfo"] andFile:file];
}];
}
- (void)updateWithNowPlayingInfo:(NSDictionary*)nowPlayingInfo {
self.titleString = nowPlayingInfo[MPMediaItemPropertyTitle];
self.playBackDurationNumber = nowPlayingInfo[MPMediaItemPropertyPlaybackDuration];
- (void)updateWithNowPlayingInfo:(NSDictionary*)nowPlayingInfo andFile:(MLFile*)file {
self.titleString = file.title ?: nowPlayingInfo[MPMediaItemPropertyTitle];
NSNumber *duration = file.duration;
if (!duration) {
float durationFloat = duration.floatValue;
duration = @(durationFloat*1000);
}
self.playBackDurationNumber = duration;
self.image.image = [VLCThumbnailsCache thumbnailForManagedObject:file];
}
- (IBAction)playPausePressed {
......@@ -95,12 +109,7 @@
- (void)setPlayBackDurationNumber:(NSNumber *)playBackDurationNumber {
if (![_playBackDurationNumber isEqualToNumber:playBackDurationNumber] || (_playBackDurationNumber==nil && playBackDurationNumber)) {
_playBackDurationNumber = playBackDurationNumber;
float duratioFloat = playBackDurationNumber.floatValue;
NSNumber *durationNumber = nil;
if (duratioFloat>0.0) {
durationNumber = @(playBackDurationNumber.floatValue*1000);
}
self.durationLabel.text = [VLCTime timeWithNumber:durationNumber].stringValue;
self.durationLabel.text = [VLCTime timeWithNumber:playBackDurationNumber].stringValue;
}
}
......
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