@javascriptcommon/react-native-track-player 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +75 -0
- package/LICENSE +21 -0
- package/android/build.gradle +34 -0
- package/android/proguard-rules.txt +3 -0
- package/android/react-native-music-control.iml +139 -0
- package/android/react-native-track-player.iml +151 -0
- package/android/src/main/AndroidManifest.xml +30 -0
- package/android/src/main/java/com/guichaguri/trackplayer/TrackPlayer.java +28 -0
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicEvents.java +55 -0
- package/android/src/main/java/com/guichaguri/trackplayer/module/MusicModule.java +298 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/HeadlessJsMediaService.java +174 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicBinder.java +47 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicManager.java +383 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/MusicService.java +271 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/Utils.java +243 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/ButtonEvents.java +148 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/metadata/MetadataManager.java +379 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/models/Track.java +141 -0
- package/android/src/main/java/com/guichaguri/trackplayer/service/models/TrackType.java +35 -0
- package/android/src/main/res/drawable-hdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_logo.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-hdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_logo.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-mdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_logo.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_logo.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxhdpi/ic_stop.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_forward.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_logo.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_next.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_pause.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_play.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_previous.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_rewind.png +0 -0
- package/android/src/main/res/drawable-xxxhdpi/ic_stop.png +0 -0
- package/index.d.ts +174 -0
- package/index.js +4 -0
- package/ios/RNTrackPlayer/Models/Capabilities.swift +17 -0
- package/ios/RNTrackPlayer/Models/MediaURL.swift +32 -0
- package/ios/RNTrackPlayer/Models/Track.swift +120 -0
- package/ios/RNTrackPlayer/RNTrackPlayer.swift +488 -0
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.h +12 -0
- package/ios/RNTrackPlayer/RNTrackPlayerBridge.m +29 -0
- package/ios/RNTrackPlayer/Support/RNTrackPlayer-Bridging-Header.h +6 -0
- package/ios/TrackPlayer.xcodeproj/project.pbxproj +495 -0
- package/ios/TrackPlayer.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
- package/ios/TrackPlayer.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
- package/ios/TrackPlayer.xcodeproj/project.xcworkspace/xcuserdata/marco.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/TrackPlayer.xcodeproj/xcuserdata/marco.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/lib/ProgressComponent.js +70 -0
- package/lib/eventTypes.js +28 -0
- package/lib/hooks.js +160 -0
- package/lib/index.js +177 -0
- package/package.json +47 -0
- package/react-native-track-player.podspec +22 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
export = RNTrackPlayer;
|
|
4
|
+
|
|
5
|
+
declare namespace RNTrackPlayer {
|
|
6
|
+
|
|
7
|
+
export type EventType =
|
|
8
|
+
| "playback-state"
|
|
9
|
+
| "playback-error"
|
|
10
|
+
| "playback-queue-ended"
|
|
11
|
+
| "playback-track-changed"
|
|
12
|
+
| "remote-play"
|
|
13
|
+
| "remote-play-id"
|
|
14
|
+
| "remote-play-search"
|
|
15
|
+
| "remote-pause"
|
|
16
|
+
| "remote-stop"
|
|
17
|
+
| "remote-skip"
|
|
18
|
+
| "remote-next"
|
|
19
|
+
| "remote-previous"
|
|
20
|
+
| "remote-jump-forward"
|
|
21
|
+
| "remote-jump-backward"
|
|
22
|
+
| "remote-seek"
|
|
23
|
+
| "remote-set-rating"
|
|
24
|
+
| "remote-duck"
|
|
25
|
+
| "remote-like"
|
|
26
|
+
| "remote-dislike"
|
|
27
|
+
| "remote-bookmark"
|
|
28
|
+
| "remote-play-pause";
|
|
29
|
+
|
|
30
|
+
export type TrackType =
|
|
31
|
+
| "default"
|
|
32
|
+
| "dash"
|
|
33
|
+
| "hls"
|
|
34
|
+
| "smoothstreaming";
|
|
35
|
+
|
|
36
|
+
type ResourceObject = any;
|
|
37
|
+
|
|
38
|
+
type State = string | number;
|
|
39
|
+
type RatingType = string | number;
|
|
40
|
+
type Capability = string | number;
|
|
41
|
+
|
|
42
|
+
type EventHandler = (type: EventType, ...args: any[]) => void;
|
|
43
|
+
export function registerEventHandler(handler: EventHandler): void;
|
|
44
|
+
|
|
45
|
+
type ServiceHandler = () => Promise<void>;
|
|
46
|
+
export function registerPlaybackService(serviceFactory: () => ServiceHandler): void;
|
|
47
|
+
|
|
48
|
+
type EmitterSubscription = { remove: () => void; };
|
|
49
|
+
export function addEventListener(type: EventType, listener: (data: any) => void): EmitterSubscription;
|
|
50
|
+
|
|
51
|
+
export interface TrackMetadata {
|
|
52
|
+
duration?: number;
|
|
53
|
+
title: string;
|
|
54
|
+
artist: string;
|
|
55
|
+
album?: string;
|
|
56
|
+
description?: string;
|
|
57
|
+
genre?: string;
|
|
58
|
+
date?: string;
|
|
59
|
+
rating?: number | boolean;
|
|
60
|
+
artwork?: string | ResourceObject;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Track extends TrackMetadata {
|
|
64
|
+
type?: TrackType;
|
|
65
|
+
userAgent?: string;
|
|
66
|
+
contentType?: string;
|
|
67
|
+
[key: string]: any;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface PlayerOptions {
|
|
71
|
+
minBuffer?: number;
|
|
72
|
+
maxBuffer?: number;
|
|
73
|
+
playBuffer?: number;
|
|
74
|
+
maxCacheSize?: number;
|
|
75
|
+
iosCategory?: 'playback' | 'playAndRecord' | 'multiRoute' | 'ambient' | 'soloAmbient' | 'record';
|
|
76
|
+
iosCategoryMode?: 'default' | 'gameChat' | 'measurement' | 'moviePlayback' | 'spokenAudio' | 'videoChat' | 'videoRecording' | 'voiceChat' | 'voicePrompt';
|
|
77
|
+
iosCategoryOptions?: Array<'mixWithOthers' | 'duckOthers' | 'interruptSpokenAudioAndMixWithOthers' | 'allowBluetooth' | 'allowBluetoothA2DP' | 'allowAirPlay' | 'defaultToSpeaker'>;
|
|
78
|
+
waitForBuffer?: boolean;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
interface FeedbackOptions {
|
|
82
|
+
/** Marks wether the option should be marked as active or "done" */
|
|
83
|
+
isActive: boolean
|
|
84
|
+
|
|
85
|
+
/** The title to give the action (relevant for iOS) */
|
|
86
|
+
title: string
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface MetadataOptions {
|
|
90
|
+
ratingType?: RatingType;
|
|
91
|
+
jumpInterval?: number;
|
|
92
|
+
likeOptions?: FeedbackOptions;
|
|
93
|
+
dislikeOptions?: FeedbackOptions;
|
|
94
|
+
bookmarkOptions?: FeedbackOptions;
|
|
95
|
+
stopWithApp?: boolean;
|
|
96
|
+
alwaysPauseOnInterruption?: boolean;
|
|
97
|
+
hideArtworkLockScreenBackground?: boolean;
|
|
98
|
+
|
|
99
|
+
capabilities?: Capability[];
|
|
100
|
+
notificationCapabilities?: Capability[];
|
|
101
|
+
compactCapabilities?: Capability[];
|
|
102
|
+
|
|
103
|
+
icon?: ResourceObject;
|
|
104
|
+
playIcon?: ResourceObject;
|
|
105
|
+
pauseIcon?: ResourceObject;
|
|
106
|
+
stopIcon?: ResourceObject;
|
|
107
|
+
previousIcon?: ResourceObject;
|
|
108
|
+
nextIcon?: ResourceObject;
|
|
109
|
+
rewindIcon?: ResourceObject;
|
|
110
|
+
forwardIcon?: ResourceObject;
|
|
111
|
+
color?: number;
|
|
112
|
+
|
|
113
|
+
placeholderImage?: ResourceObject;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// General
|
|
117
|
+
|
|
118
|
+
export function setupPlayer(options?: PlayerOptions): Promise<void>;
|
|
119
|
+
|
|
120
|
+
// Player Queue Commands
|
|
121
|
+
|
|
122
|
+
export function setNowPlaying(track: Track): Promise<void>;
|
|
123
|
+
export function updatePlayback(data: any): Promise<void>;
|
|
124
|
+
export function reset(): Promise<void>;
|
|
125
|
+
|
|
126
|
+
// Control Center / Notification Metadata Commands
|
|
127
|
+
export function updateOptions(options: MetadataOptions): Promise<void>;
|
|
128
|
+
export function updateMetadataForTrack(id: string, metadata: TrackMetadata) : Promise<void>;
|
|
129
|
+
// Components
|
|
130
|
+
|
|
131
|
+
export interface ProgressComponentState {
|
|
132
|
+
position: number;
|
|
133
|
+
bufferedPosition: number;
|
|
134
|
+
duration: number;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export class ProgressComponent<P = {}, S = {}> extends Component<P, ProgressComponentState & S> {
|
|
138
|
+
public getProgress: () => number;
|
|
139
|
+
public getBufferedProgress: () => number;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Constants
|
|
143
|
+
|
|
144
|
+
export const STATE_NONE: State;
|
|
145
|
+
export const STATE_PLAYING: State;
|
|
146
|
+
export const STATE_PAUSED: State;
|
|
147
|
+
export const STATE_STOPPED: State;
|
|
148
|
+
export const STATE_BUFFERING: State;
|
|
149
|
+
export const STATE_READY: State;
|
|
150
|
+
|
|
151
|
+
export const RATING_HEART: RatingType;
|
|
152
|
+
export const RATING_THUMBS_UP_DOWN: RatingType;
|
|
153
|
+
export const RATING_3_STARS: RatingType;
|
|
154
|
+
export const RATING_4_STARS: RatingType;
|
|
155
|
+
export const RATING_5_STARS: RatingType;
|
|
156
|
+
export const RATING_PERCENTAGE: RatingType;
|
|
157
|
+
|
|
158
|
+
export const CAPABILITY_PLAY: Capability;
|
|
159
|
+
export const CAPABILITY_PLAY_FROM_ID: Capability;
|
|
160
|
+
export const CAPABILITY_PLAY_FROM_SEARCH: Capability;
|
|
161
|
+
export const CAPABILITY_PAUSE: Capability;
|
|
162
|
+
export const CAPABILITY_STOP: Capability;
|
|
163
|
+
export const CAPABILITY_SEEK_TO: Capability;
|
|
164
|
+
export const CAPABILITY_SKIP: Capability;
|
|
165
|
+
export const CAPABILITY_SKIP_TO_NEXT: Capability;
|
|
166
|
+
export const CAPABILITY_SKIP_TO_PREVIOUS: Capability;
|
|
167
|
+
export const CAPABILITY_SET_RATING: Capability;
|
|
168
|
+
export const CAPABILITY_JUMP_FORWARD: Capability;
|
|
169
|
+
export const CAPABILITY_JUMP_BACKWARD: Capability;
|
|
170
|
+
export const CAPABILITY_LIKE: Capability;
|
|
171
|
+
export const CAPABILITY_DISLIKE: Capability;
|
|
172
|
+
export const CAPABILITY_BOOKMARK: Capability;
|
|
173
|
+
|
|
174
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Capabilities.swift
|
|
3
|
+
// RNTrackPlayer
|
|
4
|
+
//
|
|
5
|
+
// Created by David Chavez on 07.09.17.
|
|
6
|
+
// Copyright © 2017 David Chavez. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
enum Capability: String {
|
|
12
|
+
case play, pause, stop, next, previous, jumpForward, jumpBackward, seek, like, dislike, bookmark
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
enum PlayState: String {
|
|
16
|
+
case none, playing, paused, stopped
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//
|
|
2
|
+
// MediaURL.swift
|
|
3
|
+
// RNTrackPlayer
|
|
4
|
+
//
|
|
5
|
+
// Created by David Chavez on 12.08.17.
|
|
6
|
+
// Copyright © 2017 David Chavez. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import React
|
|
11
|
+
|
|
12
|
+
struct MediaURL {
|
|
13
|
+
let value: URL
|
|
14
|
+
let isLocal: Bool
|
|
15
|
+
private let originalObject: Any
|
|
16
|
+
|
|
17
|
+
init?(object: Any?) {
|
|
18
|
+
guard let object = object else { return nil }
|
|
19
|
+
originalObject = object
|
|
20
|
+
|
|
21
|
+
if let localObject = object as? [String: Any] {
|
|
22
|
+
let uri = localObject["uri"] as! String
|
|
23
|
+
isLocal = uri.lowercased().contains("http") ? false : true
|
|
24
|
+
let encodedURI = uri.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
|
|
25
|
+
value = RCTConvert.nsurl(encodedURI.replacingOccurrences(of: "file://", with: ""))
|
|
26
|
+
} else {
|
|
27
|
+
let url = object as! String
|
|
28
|
+
isLocal = url.lowercased().contains("http") ? false : true
|
|
29
|
+
value = RCTConvert.nsurl(url.replacingOccurrences(of: "file://", with: ""))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Track.swift
|
|
3
|
+
// RNTrackPlayer
|
|
4
|
+
//
|
|
5
|
+
// Created by David Chavez on 12.08.17.
|
|
6
|
+
// Copyright © 2017 David Chavez. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
import MediaPlayer
|
|
11
|
+
import AVFoundation
|
|
12
|
+
|
|
13
|
+
class Track: NSObject {
|
|
14
|
+
let id: String
|
|
15
|
+
|
|
16
|
+
@objc var title: String
|
|
17
|
+
@objc var artist: String
|
|
18
|
+
|
|
19
|
+
var date: String?
|
|
20
|
+
var desc: String?
|
|
21
|
+
var genre: String?
|
|
22
|
+
var duration: Double?
|
|
23
|
+
var skipped: Bool = false
|
|
24
|
+
var artworkURL: MediaURL?
|
|
25
|
+
let headers: [String: Any]?
|
|
26
|
+
let pitchAlgorithm: String?
|
|
27
|
+
|
|
28
|
+
@objc var album: String?
|
|
29
|
+
@objc var artwork: MPMediaItemArtwork?
|
|
30
|
+
|
|
31
|
+
private var originalObject: [String: Any]
|
|
32
|
+
|
|
33
|
+
init?(dictionary: [String: Any]) {
|
|
34
|
+
|
|
35
|
+
let id = dictionary["id"] as? String
|
|
36
|
+
let title = dictionary["title"] as? String
|
|
37
|
+
let artist = dictionary["artist"] as? String
|
|
38
|
+
|
|
39
|
+
self.id = id ?? "eSound"
|
|
40
|
+
self.title = title ?? "eSound"
|
|
41
|
+
self.artist = artist ?? "eSound"
|
|
42
|
+
|
|
43
|
+
self.date = dictionary["date"] as? String
|
|
44
|
+
self.album = dictionary["album"] as? String
|
|
45
|
+
self.genre = dictionary["genre"] as? String
|
|
46
|
+
self.desc = dictionary["description"] as? String
|
|
47
|
+
self.duration = dictionary["duration"] as? Double
|
|
48
|
+
self.headers = dictionary["headers"] as? [String: Any]
|
|
49
|
+
self.artworkURL = MediaURL(object: dictionary["artwork"])
|
|
50
|
+
self.pitchAlgorithm = dictionary["pitchAlgorithm"] as? String
|
|
51
|
+
|
|
52
|
+
self.originalObject = dictionary
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// MARK: - Public Interface
|
|
57
|
+
|
|
58
|
+
func toObject() -> [String: Any] {
|
|
59
|
+
return originalObject
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
func updateMetadata(dictionary: [String: Any]) {
|
|
63
|
+
self.title = (dictionary["title"] as? String) ?? self.title
|
|
64
|
+
self.artist = (dictionary["artist"] as? String) ?? self.artist
|
|
65
|
+
|
|
66
|
+
self.date = dictionary["date"] as? String
|
|
67
|
+
self.album = dictionary["album"] as? String
|
|
68
|
+
self.genre = dictionary["genre"] as? String
|
|
69
|
+
self.desc = dictionary["description"] as? String
|
|
70
|
+
self.duration = dictionary["duration"] as? Double
|
|
71
|
+
self.artworkURL = MediaURL(object: dictionary["artwork"])
|
|
72
|
+
|
|
73
|
+
self.originalObject = self.originalObject.merging(dictionary) { (_, new) in new }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// MARK: - AudioItem Protocol
|
|
77
|
+
|
|
78
|
+
func getArtist() -> String? {
|
|
79
|
+
return artist
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
func getTitle() -> String? {
|
|
83
|
+
return title
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func getAlbumTitle() -> String? {
|
|
87
|
+
return album
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
func getArtwork(_ handler: @escaping (UIImage?) -> Void) {
|
|
92
|
+
if let artworkURL = artworkURL?.value {
|
|
93
|
+
if(self.artworkURL?.isLocal ?? false){
|
|
94
|
+
let image = UIImage.init(contentsOfFile: artworkURL.path);
|
|
95
|
+
handler(image);
|
|
96
|
+
} else {
|
|
97
|
+
URLSession.shared.dataTask(with: artworkURL, completionHandler: { (data, _, error) in
|
|
98
|
+
if let data = data, let artwork = UIImage(data: data), error == nil {
|
|
99
|
+
handler(artwork)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
handler(nil)
|
|
103
|
+
}).resume()
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
handler(nil)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// MARK: - Authorizing Protocol
|
|
111
|
+
|
|
112
|
+
func getAssetOptions() -> [String: Any] {
|
|
113
|
+
if let headers = headers {
|
|
114
|
+
return ["AVURLAssetHTTPHeaderFieldsKey": headers]
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return [:]
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
}
|