1
- package jp .manse . offlineVideo ;
1
+ package jp .manse ;
2
2
3
3
import android .os .Handler ;
4
4
import android .os .Looper ;
5
5
import android .util .Log ;
6
6
7
+ import com .brightcove .player .edge .Catalog ;
7
8
import com .brightcove .player .edge .OfflineCallback ;
8
9
import com .brightcove .player .edge .OfflineCatalog ;
10
+ import com .brightcove .player .edge .PlaylistListener ;
11
+ import com .brightcove .player .model .Playlist ;
9
12
import com .brightcove .player .model .Video ;
10
13
import com .brightcove .player .network .DownloadStatus ;
11
14
import com .facebook .react .bridge .NativeArray ;
17
20
import java .util .ArrayList ;
18
21
import java .util .List ;
19
22
20
- import jp .manse .DefaultEventEmitter ;
23
+ import jp .manse .util . DefaultEventEmitter ;
21
24
22
- public class OfflineVideoOwner implements OfflineVideoDownloadSession .OnOfflineVideoDownloadSessionListener {
25
+ public class BrightcovePlayerAccount implements OfflineVideoDownloadSession .OnOfflineVideoDownloadSessionListener {
23
26
final private static int FPS = 40 ;
24
27
final private static String DEBUG_TAG = "brightcoveplayer" ;
25
28
final private static String ERROR_CODE = "error" ;
26
29
final private static String ERROR_MESSAGE_DUPLICATE_SESSION = "Offline video or download session already exists" ;
27
30
final private static String ERROR_MESSAGE_DELETE = "Could not delete video" ;
31
+ final private static String ERROR_MESSAGE_PLAYLIST = "Failed to load playlist" ;
28
32
final private static String CALLBACK_KEY_VIDEO_TOKEN = "videoToken" ;
29
33
final private static String CALLBACK_KEY_DOWNLOAD_PROGRESS = "downloadProgress" ;
34
+ final private static String CALLBACK_KEY_ACCOUNT_ID = "accountId" ;
35
+ final private static String CALLBACK_KEY_VIDEO_ID = "videoId" ;
36
+ final private static String CALLBACK_KEY_REFERENCE_ID = "referenceId" ;
37
+ final private static String CALLBACK_KEY_NAME = "name" ;
38
+ final private static String CALLBACK_KEY_DESCRIPTION = "description" ;
39
+ final private static String CALLBACK_KEY_DURATION = "duration" ;
30
40
31
41
private ReactApplicationContext context ;
32
42
public String accountId ;
@@ -37,13 +47,15 @@ public class OfflineVideoOwner implements OfflineVideoDownloadSession.OnOfflineV
37
47
private boolean getOfflineVideoStatusesRunning = false ;
38
48
private List <Promise > getOfflineVideoStatusesPendingPromises = new ArrayList <>();
39
49
private List <Video > allDownloadedVideos ;
50
+ private Catalog catalog ;
40
51
private OfflineCatalog offlineCatalog ;
41
52
42
- public OfflineVideoOwner (final ReactApplicationContext context , final String accountId , final String policyKey ) {
53
+ public BrightcovePlayerAccount (final ReactApplicationContext context , final String accountId , final String policyKey ) {
43
54
this .context = context ;
44
55
this .accountId = accountId ;
45
56
this .policyKey = policyKey ;
46
57
handler = new Handler (Looper .myLooper ());
58
+ this .catalog = new Catalog (DefaultEventEmitter .sharedEventEmitter , accountId , policyKey );
47
59
this .offlineCatalog = new OfflineCatalog (context , DefaultEventEmitter .sharedEventEmitter , accountId , policyKey );
48
60
this .offlineCatalog .setMeteredDownloadAllowed (true );
49
61
this .offlineCatalog .setMobileDownloadAllowed (true );
@@ -52,7 +64,7 @@ public OfflineVideoOwner(final ReactApplicationContext context, final String acc
52
64
@ Override
53
65
public void onSuccess (List <Video > videos ) {
54
66
for (Video video : videos ) {
55
- OfflineVideoDownloadSession session = new OfflineVideoDownloadSession (context , accountId , policyKey , OfflineVideoOwner .this );
67
+ OfflineVideoDownloadSession session = new OfflineVideoDownloadSession (context , accountId , policyKey , BrightcovePlayerAccount .this );
56
68
session .resumeDownload (video );
57
69
offlineVideoDownloadSessions .add (session );
58
70
}
@@ -148,6 +160,34 @@ public void onFailure(Throwable throwable) {
148
160
}
149
161
}
150
162
163
+ public void getPlaylistWithPlaylistId (String playlistId , final Promise promise ) {
164
+ catalog .findPlaylistByID (playlistId , new PlaylistListener () {
165
+ @ Override
166
+ public void onPlaylist (Playlist playlist ) {
167
+ promise .resolve (collectNativePlaylist (accountId , playlist ));
168
+ }
169
+
170
+ @ Override
171
+ public void onError (String error ) {
172
+ promise .reject (ERROR_CODE , ERROR_MESSAGE_PLAYLIST );
173
+ }
174
+ });
175
+ }
176
+
177
+ public void getPlaylistWithReferenceId (String referenceId , final Promise promise ) {
178
+ catalog .findPlaylistByReferenceID (referenceId , new PlaylistListener () {
179
+ @ Override
180
+ public void onPlaylist (Playlist playlist ) {
181
+ promise .resolve (collectNativePlaylist (accountId , playlist ));
182
+ }
183
+
184
+ @ Override
185
+ public void onError (String error ) {
186
+ promise .reject (ERROR_CODE , ERROR_MESSAGE_PLAYLIST );
187
+ }
188
+ });
189
+ }
190
+
151
191
private NativeArray collectNativeOfflineVideoStatuses () {
152
192
WritableNativeArray statuses = new WritableNativeArray ();
153
193
for (Video video : this .allDownloadedVideos ) {
@@ -174,6 +214,21 @@ private NativeArray collectNativeOfflineVideoStatuses() {
174
214
return statuses ;
175
215
}
176
216
217
+ private NativeArray collectNativePlaylist (String accountId , Playlist playlist ) {
218
+ WritableNativeArray result = new WritableNativeArray ();
219
+ for (Video video : playlist .getVideos ()) {
220
+ WritableNativeMap map = new WritableNativeMap ();
221
+ map .putString (CALLBACK_KEY_ACCOUNT_ID , accountId );
222
+ map .putString (CALLBACK_KEY_VIDEO_ID , video .getId ());
223
+ map .putString (CALLBACK_KEY_REFERENCE_ID , video .getReferenceId ());
224
+ map .putString (CALLBACK_KEY_NAME , video .getName ());
225
+ map .putString (CALLBACK_KEY_DESCRIPTION , video .getDescription ());
226
+ map .putInt (CALLBACK_KEY_DURATION , video .getDuration ());
227
+ result .pushMap (map );
228
+ }
229
+ return result ;
230
+ }
231
+
177
232
private boolean hasOfflineVideoDownloadSessionWithReferenceId (String referenceId ) {
178
233
for (OfflineVideoDownloadSession session : this .offlineVideoDownloadSessions ) {
179
234
if (referenceId .equals (session .referenceId )) return true ;
0 commit comments