├── .fetch.json
├── .gitignore
├── README.md
├── package.json
├── plugin.xml
├── src
└── ios
│ ├── MainViewController+RemoteControls.h
│ ├── MainViewController+RemoteControls.m
│ ├── RemoteControls.h
│ └── RemoteControls.m
└── www
└── RemoteControls.js
/.fetch.json:
--------------------------------------------------------------------------------
1 | {"source":{"type":"git","url":"https://github.com/shi11/RemoteControls","subdir":"."}}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .DS_Store
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | RemoteControls
2 | ==========
3 |
4 | PhoneGap / Cordova iOS plugin that allows you to use the Remote Controls as well as add metadatas in RemoteControlsInfoCenter
5 |
6 | Require
7 | -------
8 | - PhoneGap / Cordova 3.x
9 |
10 | ## Installation
11 |
12 | Add the plugin much like any other:
13 |
14 | `cordova plugin add com.rd11.remote-controls`
15 |
16 | ## Supported Platforms
17 | - iOS
18 |
19 | ## Methods
20 | - window.remoteControls.updateMetas
21 |
22 | ## Events
23 | - "remote-event"
24 |
25 | ### Example
26 | ```javascript
27 | function onDeviceReady() {
28 | artist = "Daft Punk";
29 | title = "One More Time";
30 | album = "Discovery";
31 | image = "path_within_documents_storage OR url_starting_with_http_or_https";
32 | duration = my_media.getDuration();
33 | elapsedTime = my_media.getElapsedTime();
34 |
35 | var params = [artist, title, album, image, duration, elapsedTime];
36 | window.remoteControls.updateMetas(function(success){
37 | console.log(success);
38 | }, function(fail){
39 | console.log(fail);
40 | }, params);
41 | }
42 |
43 | //listen for the event
44 | document.addEventListener("remote-event", function(event) {
45 | //do something
46 | })
47 |
48 | ```
49 |
50 | ## RemoteControls License
51 |
52 | The MIT License
53 |
54 | Copyright (c) 2013 Seth Hillinger (http://github.com/shi11)
55 |
56 | ## Metadata License
57 |
58 | The MIT License
59 |
60 | Copyright (c) 2013 François LASSERRE (http://github.com/choiz)
61 |
62 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
63 |
64 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
65 |
66 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "com.rd11.remote-controls",
3 | "version": "1.0.1",
4 | "description": "iOS lock-screen remote-controls and now playing display.",
5 | "cordova": {
6 | "id": "com.rd11.remote-controls",
7 | "platforms": [
8 | "ios"
9 | ]
10 | },
11 | "repository": {
12 | "type": "git",
13 | "url": "git+https://github.com/shi11/RemoteControls.git"
14 | },
15 | "keywords": [
16 | "lockscreen",
17 | "media",
18 | "now",
19 | "playing",
20 | "ecosystem:cordova",
21 | "cordova-ios"
22 | ],
23 | "engines": [
24 | {
25 | "name": "cordova",
26 | "version": ">=3.0.0"
27 | }
28 | ],
29 | "author": "Seth Hillinger",
30 | "license": "MIT License",
31 | "bugs": {
32 | "url": "https://github.com/shi11/RemoteControls/issues"
33 | },
34 | "homepage": "https://github.com/shi11/RemoteControls#readme"
35 | }
36 |
--------------------------------------------------------------------------------
/plugin.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 | RemoteControls
11 | lockscreen,media,now,playing
12 | https://github.com/shi11/RemoteControls.git
13 | https://github.com/shi11/RemoteControls/issues
14 |
15 | iOS lock-screen remote-controls and now playing display.
16 |
17 |
18 |
19 |
20 |
21 | Seth Hillinger, François LASSERRE, Michael GAUTHIER
22 |
23 | MIT License
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/src/ios/MainViewController+RemoteControls.h:
--------------------------------------------------------------------------------
1 | //
2 | // MainViewController+RemoteControls.h
3 | //
4 | // Created by Julio Cesar Sanchez Hernandez on 4/3/16.
5 | //
6 | //
7 |
8 | #import "MainViewController.h"
9 |
10 | @interface MainViewController (RemoteControls)
11 |
12 | @end
13 |
--------------------------------------------------------------------------------
/src/ios/MainViewController+RemoteControls.m:
--------------------------------------------------------------------------------
1 | //
2 | // MainViewController+RemoteControls.m
3 | //
4 | // Created by Julio Cesar Sanchez Hernandez on 4/3/16.
5 | //
6 | //
7 |
8 | #import "MainViewController+RemoteControls.h"
9 |
10 | @implementation MainViewController (RemoteControls)
11 |
12 | - (void)remoteControlReceivedWithEvent:(UIEvent *)receivedEvent {
13 | [[NSNotificationCenter defaultCenter] postNotificationName:@"receivedEvent" object:receivedEvent];
14 | }
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/src/ios/RemoteControls.h:
--------------------------------------------------------------------------------
1 | //
2 | // NowPlaying.h
3 | // Now Playing Cordova Plugin
4 | //
5 | // Created by François LASSERRE on 12/05/13.
6 | // Copyright 2013 François LASSERRE. All rights reserved.
7 | // MIT Licensed
8 | //
9 |
10 | #import
11 | #import
12 | #import
13 | #import
14 |
15 | @interface RemoteControls : CDVPlugin {
16 | }
17 |
18 | - (void)updateMetas:(CDVInvokedUrlCommand*)command;
19 | - (void)receiveRemoteEvent:(NSNotification *)notification;
20 |
21 | @end
22 |
--------------------------------------------------------------------------------
/src/ios/RemoteControls.m:
--------------------------------------------------------------------------------
1 | //
2 | // RemoteControls.m
3 | // Now Playing Cordova Plugin
4 | //
5 | // Created by François LASSERRE on 12/05/13.
6 | // Copyright 2013 François LASSERRE. All rights reserved.
7 | // MIT Licensed
8 | //
9 |
10 | #import "RemoteControls.h"
11 |
12 | @implementation RemoteControls
13 |
14 | static RemoteControls *remoteControls = nil;
15 |
16 | - (void)pluginInitialize
17 | {
18 | NSLog(@"RemoteControls plugin init.");
19 | [[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
20 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveRemoteEvent:) name:@"receivedEvent" object:nil];
21 |
22 | }
23 |
24 | - (void)updateMetas:(CDVInvokedUrlCommand*)command
25 | {
26 | NSString *artist = [command.arguments objectAtIndex:0];
27 | NSString *title = [command.arguments objectAtIndex:1];
28 | NSString *album = [command.arguments objectAtIndex:2];
29 | NSString *cover = [command.arguments objectAtIndex:3];
30 | NSNumber *duration = [command.arguments objectAtIndex:4];
31 | NSNumber *elapsed = [command.arguments objectAtIndex:5];
32 |
33 | // async cover loading
34 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
35 | UIImage *image = nil;
36 | // check whether cover path is present
37 | if (![cover isEqual: @""]) {
38 | // cover is remote file
39 | if ([cover hasPrefix: @"http://"] || [cover hasPrefix: @"https://"]) {
40 | NSURL *imageURL = [NSURL URLWithString:cover];
41 | NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
42 | image = [UIImage imageWithData:imageData];
43 | }
44 | // cover is full path to local file
45 | else if ([cover hasPrefix: @"file://"]) {
46 | NSString *fullPath = [cover stringByReplacingOccurrencesOfString:@"file://" withString:@""];
47 | BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
48 | if (fileExists) {
49 | image = [[UIImage alloc] initWithContentsOfFile:fullPath];
50 | }
51 | }
52 | // cover is relative path to local file
53 | else {
54 | NSString *basePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
55 | NSString *fullPath = [NSString stringWithFormat:@"%@%@", basePath, cover];
56 | BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:fullPath];
57 | if (fileExists) {
58 | image = [UIImage imageNamed:fullPath];
59 | }
60 | }
61 | }
62 | else {
63 | // default named "no-image"
64 | image = [UIImage imageNamed:@"no-image"];
65 | }
66 | // check whether image is loaded
67 | CGImageRef cgref = [image CGImage];
68 | CIImage *cim = [image CIImage];
69 | if (cim != nil || cgref != NULL) {
70 | dispatch_async(dispatch_get_main_queue(), ^{
71 | if (NSClassFromString(@"MPNowPlayingInfoCenter")) {
72 | MPMediaItemArtwork *artwork = [[MPMediaItemArtwork alloc] initWithImage: image];
73 | MPNowPlayingInfoCenter *center = [MPNowPlayingInfoCenter defaultCenter];
74 | center.nowPlayingInfo = [NSDictionary dictionaryWithObjectsAndKeys:
75 | artist, MPMediaItemPropertyArtist,
76 | title, MPMediaItemPropertyTitle,
77 | album, MPMediaItemPropertyAlbumTitle,
78 | artwork, MPMediaItemPropertyArtwork,
79 | duration, MPMediaItemPropertyPlaybackDuration,
80 | elapsed, MPNowPlayingInfoPropertyElapsedPlaybackTime,
81 | [NSNumber numberWithInt:1], MPNowPlayingInfoPropertyPlaybackRate, nil];
82 | }
83 | });
84 | }
85 | });
86 | }
87 |
88 |
89 | - (void)receiveRemoteEvent:(NSNotification *)notification {
90 |
91 | UIEvent * receivedEvent = notification.object;
92 |
93 | if (receivedEvent.type == UIEventTypeRemoteControl) {
94 |
95 | NSString *subtype = @"other";
96 |
97 | switch (receivedEvent.subtype) {
98 |
99 | case UIEventSubtypeRemoteControlTogglePlayPause:
100 | NSLog(@"playpause clicked.");
101 | subtype = @"playpause";
102 | break;
103 |
104 | case UIEventSubtypeRemoteControlPlay:
105 | NSLog(@"play clicked.");
106 | subtype = @"play";
107 | break;
108 |
109 | case UIEventSubtypeRemoteControlPause:
110 | NSLog(@"nowplaying pause clicked.");
111 | subtype = @"pause";
112 | break;
113 |
114 | case UIEventSubtypeRemoteControlPreviousTrack:
115 | //[self previousTrack: nil];
116 | NSLog(@"prev clicked.");
117 | subtype = @"prevTrack";
118 | break;
119 |
120 | case UIEventSubtypeRemoteControlNextTrack:
121 | NSLog(@"next clicked.");
122 | subtype = @"nextTrack";
123 | //[self nextTrack: nil];
124 | break;
125 |
126 | default:
127 | break;
128 | }
129 |
130 | NSDictionary *dict = @{@"subtype": subtype};
131 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options: 0 error: nil];
132 | NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
133 | NSString *jsStatement = [NSString stringWithFormat:@"if(window.remoteControls)remoteControls.receiveRemoteEvent(%@);", jsonString];
134 |
135 | #ifdef __CORDOVA_4_0_0
136 | [self.webViewEngine evaluateJavaScript:jsStatement completionHandler:nil];
137 | #else
138 | [self.webView stringByEvaluatingJavaScriptFromString:jsStatement];
139 | #endif
140 |
141 | }
142 | }
143 |
144 |
145 | -(void)dealloc {
146 | [[UIApplication sharedApplication] endReceivingRemoteControlEvents];
147 | [[NSNotificationCenter defaultCenter] removeObserver:self name:@"receivedEvent" object:nil];
148 | }
149 |
150 | @end
151 |
--------------------------------------------------------------------------------
/www/RemoteControls.js:
--------------------------------------------------------------------------------
1 | //
2 | // RemoteControls.js
3 | // Remote Control Cordova Plugin
4 |
5 | // remoteControls created by Seth Hillinger on 2/21/14.
6 | // Copyright 2013 Seth Hillinger. All rights reserved.
7 |
8 | // updateMetas created by François LASSERRE on 12/05/13.
9 | // Copyright 2013 François LASSERRE. All rights reserved.
10 | // MIT Licensed
11 | //
12 |
13 |
14 | //------------------------------------------------------------------------------
15 | // object that we're exporting
16 | //------------------------------------------------------------------------------
17 | var remoteControls = module.exports;
18 |
19 | //params = [artist, title, album, cover, duration]
20 | remoteControls.updateMetas = function(success, fail, params) {
21 | cordova.exec(success, fail, 'RemoteControls', 'updateMetas', params);
22 | };
23 |
24 | remoteControls.receiveRemoteEvent = function(event) {
25 | var ev = document.createEvent('HTMLEvents');
26 | ev.remoteEvent = event;
27 | ev.initEvent('remote-event', true, true, arguments);
28 | document.dispatchEvent(ev);
29 | }
--------------------------------------------------------------------------------