Skip to content

Commit 3f7f409

Browse files
committed
remove deprecated functions
1 parent 7445f7b commit 3f7f409

7 files changed

+46
-58
lines changed

demo/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"typescript": "^3.7.5"
2121
},
2222
"scripts": {
23+
"tslint": "tslint --config '../tslint.json' -p tsconfig.json 'app/**/*.ts' --exclude '**/node_modules/**'",
2324
"ci.tslint": "npm i && tslint --config '../tslint.json' 'app/**/*.ts' --exclude '**/node_modules/**'"
2425
}
2526
}

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"lint": "npm-run-all format:check tslint",
1818
"test.android": "(cd src && npm i && npx tsc) && npm run tslint && cd demo && tns build android && tns test android --justlaunch",
1919
"test.ios": "(cd src && npm i && npx tsc) && npm run tslint && cd demo && tns build ios && tns test ios --justlaunch",
20-
"tslint": "tslint 'src/**/*.ts' 'demo/src/**/*.ts' --config tslint.json --exclude \"**/node_modules/**\"",
20+
"tslint": "(cd src && npm run tslint) && (cd demo && npm run tslint)",
2121
"postinstall": "cd src && ([ \"$npm_config_refer\" = \"ci\" ] && npm ci || npm i)"
2222
},
2323
"repository": {
@@ -51,7 +51,6 @@
5151
"prettier": "^1.19.1",
5252
"rimraf": "^3.0.2",
5353
"tns-platform-declarations": "^6.3.2",
54-
"tslint": "^6.0.0",
5554
"typescript": "^3.7.5"
5655
},
5756
"dependencies": {}

src/audioplayer.ios.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/// <reference path="./native-definitions/ios.d.ts" />
22

3-
import { ImageSource, isFileOrResourcePath } from '@nativescript/core/image-source';
3+
import { ImageSource } from '@nativescript/core/image-source';
44
import * as trace from '@nativescript/core/trace';
5+
import * as utils from '@nativescript/core/utils/utils';
56
import { CommonAudioPlayer } from './audioplayer-common';
6-
import { MediaTrack, notaAudioCategory, PlaybackEvent, Playlist } from './audioplayer.types';
7+
import { MediaTrack, notaAudioCategory, Playlist } from './audioplayer.types';
78

89
class AudioPlayerDelegateImpl extends NSObject implements AudioPlayerDelegate {
910
public static ObjCProtocols = [AudioPlayerDelegate];
@@ -511,7 +512,7 @@ export class TNSAudioPlayer extends CommonAudioPlayer {
511512
this._isRetrievingArtwork = true;
512513

513514
try {
514-
const image = isFileOrResourcePath(artworkUrl) ? ImageSource.fromFileOrResourceSync(artworkUrl) : await ImageSource.fromUrl(artworkUrl);
515+
const image = utils.isFileOrResourcePath(artworkUrl) ? ImageSource.fromFileOrResourceSync(artworkUrl) : await ImageSource.fromUrl(artworkUrl);
515516
if (this.getCurrentMediaTrack()?.albumArtUrl === artworkUrl) {
516517
const artwork = MPMediaItemArtwork.alloc().initWithImage(image.ios);
517518
this._cachedCover = { url: artworkUrl, artwork };

src/media-service.android.ts

+37-51
Original file line numberDiff line numberDiff line change
@@ -176,40 +176,45 @@ export namespace dk {
176176
return this._playlist?.tracks?.[index];
177177
}
178178

179+
private lastPosition: number;
180+
private lastWindowIndex: number;
181+
private _handleTimeChange() {
182+
const player = this.exoPlayer;
183+
if (!player) {
184+
if (trace.isEnabled()) {
185+
trace.write(`${this.cls}._onPlaying() - no player stop timeChangeInterval`, notaAudioCategory);
186+
}
187+
188+
clearInterval(this._timeChangeInterval);
189+
190+
return;
191+
}
192+
193+
const windowIndex = player.getCurrentWindowIndex();
194+
let position = player.getCurrentPosition();
195+
const duration = player.getDuration();
196+
197+
if (this.lastPosition !== position || this.lastWindowIndex !== windowIndex) {
198+
this.owner?._onTimeChanged(position, duration, windowIndex);
199+
200+
this.lastPosition = position;
201+
this.lastWindowIndex = windowIndex;
202+
}
203+
}
204+
179205
public _onPlaying() {
180206
if (trace.isEnabled()) {
181207
trace.write(`${this.cls}._onPlaying()`, notaAudioCategory);
182208
}
183209
clearInterval(this._timeChangeInterval);
184210

185-
let lastCurrentTime: number;
186-
let lastPlaylistIndex: number;
187211
this._timeChangeInterval = setInterval(() => {
188-
const exoPlayer = this.exoPlayer;
189-
if (!exoPlayer) {
190-
if (trace.isEnabled()) {
191-
trace.write(`${this.cls}._onPlaying() - no player stop timeChangeInterval`, notaAudioCategory);
192-
}
193-
194-
clearInterval(this._timeChangeInterval);
195-
196-
return;
197-
}
198-
199-
const currentPlaylistIndex = exoPlayer.getCurrentWindowIndex();
200-
const currentTime = exoPlayer.getCurrentPosition();
201-
const duration = exoPlayer.getDuration();
202-
203-
if (lastCurrentTime !== currentTime || lastPlaylistIndex !== currentPlaylistIndex) {
204-
this.owner?._onTimeChanged(currentTime, duration, currentPlaylistIndex);
205-
206-
lastCurrentTime = currentTime;
207-
lastPlaylistIndex = currentPlaylistIndex;
208-
}
212+
this._handleTimeChange();
209213
}, 100);
210214

211215
this._mediaSession?.setActive(true);
212216

217+
this._handleTimeChange();
213218
this.owner?._onPlaying();
214219
}
215220

@@ -368,20 +373,13 @@ export namespace dk {
368373
trace.write(`${this.cls}.onStartCommand(${intent}, ${flags}, ${startId})`, notaAudioCategory);
369374
}
370375

371-
if (android.os.Build.VERSION.SDK_INT >= 24 && this._mediaSession) {
376+
if (this._mediaSession) {
372377
androidx.media.session.MediaButtonReceiver.handleIntent(this._mediaSession, intent);
373378
}
374379

375380
return super.onStartCommand(intent, flags, startId);
376381
}
377382

378-
public onStart(intent: android.content.Intent, startId: number) {
379-
if (trace.isEnabled()) {
380-
trace.write(`${this.cls}.onStart(${intent}, ${startId})`, notaAudioCategory);
381-
}
382-
super.onStart(intent, startId);
383-
}
384-
385383
public setOwner(owner: TNSAudioPlayer) {
386384
if (trace.isEnabled()) {
387385
trace.write(`${this.cls}.setOwner()`, notaAudioCategory);
@@ -1164,6 +1162,14 @@ function ensureNativeClasses() {
11641162
return global.__native(this);
11651163
}
11661164

1165+
public onNotificationPosted(notificationId: number, notification: android.app.Notification, ongoing?: boolean) {
1166+
if (trace.isEnabled()) {
1167+
trace.write(`${this.cls}.onNotificationPosted(${notificationId}, ${notification}, ${ongoing})`, notaAudioCategory);
1168+
}
1169+
1170+
this.owner?._handleNotificationPosted(notificationId, notification);
1171+
}
1172+
11671173
public onNotificationCancelled(notificationId: number, dismissedByUser?: boolean) {
11681174
if (trace.isEnabled()) {
11691175
trace.write(`${this.cls}.NotificationListener(id=${notificationId}, dismissedByUser=${dismissedByUser})`, notaAudioCategory);
@@ -1180,26 +1186,6 @@ function ensureNativeClasses() {
11801186

11811187
this.owner?.stopSelf();
11821188
}
1183-
public onNotificationPosted(notificationId: number, notification: android.app.Notification, ongoing?: boolean) {
1184-
if (trace.isEnabled()) {
1185-
trace.write(`${this.cls}.onNotificationPosted(${notificationId}, ${notification}, ${ongoing})`, notaAudioCategory);
1186-
}
1187-
1188-
this.owner?._handleNotificationPosted(notificationId, notification);
1189-
}
1190-
1191-
public onNotificationStarted(notificationId: number, notification: android.app.Notification) {
1192-
// Deprecated
1193-
if (trace.isEnabled()) {
1194-
trace.write(
1195-
`${this.cls}.onNotificationStarted(${notificationId}, ${notification}) is deprecated - why was this called?`,
1196-
notaAudioCategory,
1197-
trace.messageType.warn,
1198-
);
1199-
}
1200-
1201-
this.owner?._handleNotificationPosted(notificationId, notification);
1202-
}
12031189
}
12041190

12051191
TNSNotificationListener = TNSNotificationListenerImpl;

src/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"readmeFilename": "README.md",
4040
"scripts": {
4141
"format:check": "prettier -c --config $(git rev-parse --show-toplevel)/.prettierrc.json './**/*.ts'",
42-
"tslint": "tslint './**/*.ts' --config $(git rev-parse --show-toplevel)/tslint.json --exclude \"**/node_modules/**\"",
42+
"tslint": "tslint './**/*.ts' --config $(git rev-parse --show-toplevel)/tslint.json -p tsconfig.json --exclude \"**/node_modules/**\"",
4343
"lint": "npm-run-all format:check tslint",
4444
"build": "tsc"
4545
},

src/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"noImplicitReturns": true,
2222
"noImplicitUseStrict": false,
2323
"noFallthroughCasesInSwitch": true,
24-
"incremental": true,
24+
"incremental": true
2525
},
2626
"exclude": [
2727
"node_modules",

tslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
]
88
},
99
"rules": {
10+
"deprecation": true,
1011
"no-return-await": true,
1112
"newline-before-return": true,
1213
"no-console": true,

0 commit comments

Comments
 (0)