-
Notifications
You must be signed in to change notification settings - Fork 454
Expand file tree
/
Copy pathYouTubeManager.java
More file actions
157 lines (132 loc) · 4.83 KB
/
Copy pathYouTubeManager.java
File metadata and controls
157 lines (132 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package com.inprogress.reactnativeyoutube;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.SimpleViewManager;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;
import java.util.Map;
public class YouTubeManager extends SimpleViewManager<YouTubeView> {
private static final int COMMAND_SEEK_TO = 1;
private static final int COMMAND_NEXT_VIDEO = 2;
private static final int COMMAND_PREVIOUS_VIDEO = 3;
private static final int COMMAND_PLAY_VIDEO_AT = 4;
@Override
public String getName() {
return "ReactYouTube";
}
@Override
protected YouTubeView createViewInstance(ThemedReactContext themedReactContext) {
return new YouTubeView(themedReactContext);
}
@Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of(
"seekTo",
COMMAND_SEEK_TO,
"nextVideo",
COMMAND_NEXT_VIDEO,
"previousVideo",
COMMAND_PREVIOUS_VIDEO,
"playVideoAt",
COMMAND_PLAY_VIDEO_AT
);
}
@Override
public void receiveCommand(YouTubeView view, int commandType, @Nullable ReadableArray args) {
Assertions.assertNotNull(view);
Assertions.assertNotNull(args);
switch (commandType) {
case COMMAND_SEEK_TO: {
view.seekTo(args.getInt(0));
return;
}
case COMMAND_NEXT_VIDEO: {
view.nextVideo();
return;
}
case COMMAND_PREVIOUS_VIDEO: {
view.previousVideo();
return;
}
case COMMAND_PLAY_VIDEO_AT: {
view.playVideoAt(args.getInt(0));
return;
}
default:
throw new IllegalArgumentException(
String.format("Unsupported command %d received by %s.", commandType, getClass().getSimpleName())
);
}
}
@Override
public @Nullable
Map<String, Object> getExportedCustomDirectEventTypeConstants() {
return MapBuilder.of(
"error",
(Object) MapBuilder.of("registrationName", "onYouTubeError"),
"ready",
(Object) MapBuilder.of("registrationName", "onYouTubeReady"),
"state",
(Object) MapBuilder.of("registrationName", "onYouTubeChangeState"),
"quality",
(Object) MapBuilder.of("registrationName", "onYouTubeChangeQuality"),
"fullscreen",
(Object) MapBuilder.of("registrationName", "onYouTubeChangeFullscreen")
);
}
public int getCurrentTime(YouTubeView view) {
return view.getCurrentTime();
}
public int getDuration(YouTubeView view) {
return view.getDuration();
}
public int getVideosIndex(YouTubeView view) {
return view.getVideosIndex();
}
@ReactProp(name = "apiKey")
public void setApiKey(YouTubeView view, @Nullable String param) {
view.setApiKey(param);
}
@ReactProp(name = "videoId")
public void setPropVideoId(YouTubeView view, @Nullable String param) {
view.setVideoId(param);
}
@ReactProp(name = "videoIds")
public void setPropVideoIds(YouTubeView view, @Nullable ReadableArray param) {
view.setVideoIds(param);
}
@ReactProp(name = "playlistId")
public void setPropPlaylistId(YouTubeView view, @Nullable String param) {
view.setPlaylistId(param);
}
@ReactProp(name = "play")
public void setPropPlay(YouTubeView view, @Nullable boolean param) {
view.setPlay(param);
}
@ReactProp(name = "loop")
public void setPropLoop(YouTubeView view, @Nullable boolean param) {
view.setLoop(param);
}
@ReactProp(name = "fullscreen")
public void setPropFullscreen(YouTubeView view, @Nullable boolean param) {
view.setFullscreen(param);
}
@ReactProp(name = "fullscreenControlFlags")
public void setPropFullscreenControlFlags(YouTubeView view, int flags) {
view.setFullscreenControlFlags(flags);
}
@ReactProp(name = "controls")
public void setPropControls(YouTubeView view, @Nullable int param) {
view.setControls(param);
}
@ReactProp(name = "showFullscreenButton")
public void setPropShowFullscreenButton(YouTubeView view, @Nullable boolean param) {
view.setShowFullscreenButton(param);
}
@ReactProp(name = "resumePlayAndroid")
public void setPropResumePlay(YouTubeView view, @Nullable boolean param) {
view.setResumePlay(param);
}
}