cordova-plugin-media3 1.1.1 → 1.1.3
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/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/LayoutProvider.java +9 -9
- package/src/android/Player.java +109 -116
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
<framework src="androidx.media3:media3-decoder:1.2.1"/>
|
|
28
28
|
<framework src="androidx.media3:media3-session:1.2.1"/>
|
|
29
29
|
<framework src="org.jellyfin.media3:media3-ffmpeg-decoder:1.2.1+1"/>
|
|
30
|
-
<framework src="com.squareup.picasso:picasso:2.
|
|
30
|
+
<framework src="com.squareup.picasso:picasso:2.8"/>
|
|
31
31
|
|
|
32
32
|
<config-file target="res/xml/config.xml" parent="/*">
|
|
33
33
|
<feature name="ExoPlayer">
|
|
@@ -29,8 +29,8 @@ import android.util.*;
|
|
|
29
29
|
import android.view.*;
|
|
30
30
|
import android.widget.*;
|
|
31
31
|
|
|
32
|
-
import
|
|
33
|
-
import
|
|
32
|
+
import androidx.media3.common.ForwardingPlayer;
|
|
33
|
+
import androidx.media3.ui.*;
|
|
34
34
|
import java.lang.String;
|
|
35
35
|
|
|
36
36
|
import org.json.*;
|
|
@@ -51,8 +51,8 @@ public class LayoutProvider {
|
|
|
51
51
|
return view;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
public static
|
|
55
|
-
|
|
54
|
+
public static PlayerView getExoPlayerView(Activity activity, Configuration config) {
|
|
55
|
+
PlayerView view = new PlayerView(activity);
|
|
56
56
|
view.setLayoutParams(new LinearLayout.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
|
|
57
57
|
if (config.isAspectRatioFillScreen()) {
|
|
58
58
|
view.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
|
|
@@ -67,7 +67,7 @@ public class LayoutProvider {
|
|
|
67
67
|
return view;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public static void setupController(
|
|
70
|
+
public static void setupController(PlayerView parentView, Activity activity, JSONObject controller) {
|
|
71
71
|
if (null != controller) {
|
|
72
72
|
parentView.setUseController(true);
|
|
73
73
|
setupButtons(parentView, activity, controller);
|
|
@@ -79,7 +79,7 @@ public class LayoutProvider {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
private static void setupButtons(
|
|
82
|
+
private static void setupButtons(PlayerView parentView, Activity activity, JSONObject controller) {
|
|
83
83
|
String packageName = activity.getPackageName();
|
|
84
84
|
String buttonsColor = controller.optString("buttonsColor");
|
|
85
85
|
|
|
@@ -115,7 +115,7 @@ public class LayoutProvider {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
private static void setupBar(
|
|
118
|
+
private static void setupBar(PlayerView parentView, Activity activity, JSONObject controller) {
|
|
119
119
|
String streamTitle = controller.optString("streamTitle", null);
|
|
120
120
|
String streamDescription = controller.optString("streamDescription", null);
|
|
121
121
|
String streamImage = controller.optString("streamImage", null);
|
|
@@ -170,7 +170,7 @@ public class LayoutProvider {
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
private static void setupBuffering(
|
|
173
|
+
private static void setupBuffering(PlayerView parentView, Activity activity, JSONObject controller) {
|
|
174
174
|
String bufferingColor = controller.optString("bufferingColor");
|
|
175
175
|
ProgressBar bufferingBar = (ProgressBar)findView(parentView, activity, "exo_buffering");
|
|
176
176
|
if (null != bufferingBar && null != bufferingColor) {
|
|
@@ -178,7 +178,7 @@ public class LayoutProvider {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
public static void setBufferingVisibility(
|
|
181
|
+
public static void setBufferingVisibility(PlayerView parentView, Activity activity, boolean visible) {
|
|
182
182
|
ProgressBar progressBar = (ProgressBar)findView(parentView, activity, "exo_buffering");
|
|
183
183
|
if (null != progressBar) {
|
|
184
184
|
progressBar.setVisibility(visible ? View.VISIBLE : View.GONE);
|
package/src/android/Player.java
CHANGED
|
@@ -49,6 +49,7 @@ import androidx.media3.datasource.*;
|
|
|
49
49
|
import androidx.media3.common.util.*;
|
|
50
50
|
import androidx.media3.exoplayer.trackselection.*;
|
|
51
51
|
import androidx.media3.exoplayer.DefaultRenderersFactory;
|
|
52
|
+
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter;
|
|
52
53
|
|
|
53
54
|
import com.google.common.collect.ImmutableList;
|
|
54
55
|
|
|
@@ -64,7 +65,7 @@ public class Player {
|
|
|
64
65
|
private final Configuration config;
|
|
65
66
|
private Dialog dialog;
|
|
66
67
|
private ExoPlayer exoPlayer;
|
|
67
|
-
private
|
|
68
|
+
private PlayerView exoView;
|
|
68
69
|
private CordovaWebView webView;
|
|
69
70
|
private int controllerVisibility;
|
|
70
71
|
private boolean paused = false;
|
|
@@ -82,7 +83,7 @@ public class Player {
|
|
|
82
83
|
this.audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
|
|
83
84
|
}
|
|
84
85
|
|
|
85
|
-
private
|
|
86
|
+
private Player.Listener playerEventListener = new Player.Listener() {
|
|
86
87
|
@Override
|
|
87
88
|
public void onIsLoadingChanged(boolean isLoading) {
|
|
88
89
|
JSONObject payload = Payload.loadingEvent(Player.this.exoPlayer, isLoading);
|
|
@@ -103,14 +104,14 @@ public class Player {
|
|
|
103
104
|
@Override
|
|
104
105
|
public void onPlaybackStateChanged(int playbackState) {
|
|
105
106
|
if (config.getShowBuffering()) {
|
|
106
|
-
LayoutProvider.setBufferingVisibility(exoView, activity, playbackState ==
|
|
107
|
+
LayoutProvider.setBufferingVisibility(exoView, activity, playbackState == Player.STATE_BUFFERING);
|
|
107
108
|
}
|
|
108
109
|
JSONObject payload = Payload.stateEvent(Player.this.exoPlayer, playbackState, Player.this.controllerVisibility == View.VISIBLE);
|
|
109
110
|
new CallbackResponse(Player.this.callbackContext).send(PluginResult.Status.OK, payload, true);
|
|
110
111
|
}
|
|
111
112
|
|
|
112
113
|
@Override
|
|
113
|
-
public void onPositionDiscontinuity(@NonNull PositionInfo oldPosition, @NonNull PositionInfo newPosition, int reason) {
|
|
114
|
+
public void onPositionDiscontinuity(@NonNull Player.PositionInfo oldPosition, @NonNull Player.PositionInfo newPosition, int reason) {
|
|
114
115
|
JSONObject payload = Payload.positionDiscontinuityEvent(Player.this.exoPlayer, reason);
|
|
115
116
|
new CallbackResponse(Player.this.callbackContext).send(PluginResult.Status.OK, payload, true);
|
|
116
117
|
}
|
|
@@ -195,7 +196,7 @@ public class Player {
|
|
|
195
196
|
}
|
|
196
197
|
};
|
|
197
198
|
|
|
198
|
-
private
|
|
199
|
+
private PlayerView.ControllerVisibilityListener playbackControlVisibilityListener = new PlayerView.ControllerVisibilityListener() {
|
|
199
200
|
@Override
|
|
200
201
|
public void onVisibilityChanged(int visibility) {
|
|
201
202
|
Player.this.controllerVisibility = visibility;
|
|
@@ -318,7 +319,7 @@ public class Player {
|
|
|
318
319
|
|
|
319
320
|
|
|
320
321
|
/* Build with extyentions ffmpeg */
|
|
321
|
-
|
|
322
|
+
DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(this.activity)
|
|
322
323
|
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
|
|
323
324
|
|
|
324
325
|
// // /* lunch normal exoplayer player */
|
|
@@ -591,7 +592,7 @@ public class Player {
|
|
|
591
592
|
|
|
592
593
|
public JSONObject getPlayerState() {
|
|
593
594
|
return Payload.stateEvent(exoPlayer,
|
|
594
|
-
null != exoPlayer ? exoPlayer.getPlaybackState() :
|
|
595
|
+
null != exoPlayer ? exoPlayer.getPlaybackState() : Player.STATE_ENDED,
|
|
595
596
|
Player.this.controllerVisibility == View.VISIBLE);
|
|
596
597
|
}
|
|
597
598
|
|
|
@@ -649,67 +650,63 @@ public class Player {
|
|
|
649
650
|
public JSONObject setAudioTrack(int trackId) {
|
|
650
651
|
JSONObject response = new JSONObject();
|
|
651
652
|
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
response.put("message", "No current tracks found");
|
|
660
|
-
|
|
661
|
-
} catch (JSONException e) {
|
|
662
|
-
Log.e(TAG, "Error creating response JSON", e);
|
|
663
|
-
}
|
|
653
|
+
DefaultTrackSelector trackSelector = (DefaultTrackSelector) exoPlayer.getTrackSelector();
|
|
654
|
+
Tracks currentTracks = exoPlayer.getCurrentTracks();
|
|
655
|
+
|
|
656
|
+
if (currentTracks == null) {
|
|
657
|
+
try {
|
|
658
|
+
response.put("success", true);
|
|
659
|
+
response.put("message", "No current tracks found");
|
|
664
660
|
|
|
665
|
-
|
|
661
|
+
} catch (JSONException e) {
|
|
662
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
666
663
|
}
|
|
667
664
|
|
|
668
|
-
|
|
669
|
-
|
|
665
|
+
return response;
|
|
666
|
+
}
|
|
670
667
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
// Apply the selection
|
|
687
|
-
exoPlayer.setTrackSelectionParameters(builder.build());
|
|
668
|
+
for (Tracks.Group group : currentTracks.getGroups()) {
|
|
669
|
+
if (group.getType() == C.TRACK_TYPE_AUDIO) {
|
|
670
|
+
for (int i = 0; i < group.length; i++) {
|
|
671
|
+
try {
|
|
672
|
+
Format format = group.getTrackFormat(i);
|
|
673
|
+
int format_id = Integer.parseInt(format.id);
|
|
674
|
+
|
|
675
|
+
if (trackId == format_id) {
|
|
676
|
+
// response.put("Founded " + i, format.toString());
|
|
677
|
+
// Create track selection override
|
|
678
|
+
TrackSelectionParameters.Builder builder = exoPlayer.getTrackSelectionParameters().buildUpon();
|
|
679
|
+
builder.clearOverridesOfType(C.TRACK_TYPE_AUDIO);
|
|
680
|
+
TrackSelectionOverride override = new TrackSelectionOverride(group.getMediaTrackGroup(), i);
|
|
681
|
+
builder.addOverride(override);
|
|
688
682
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
683
|
+
// Apply the selection
|
|
684
|
+
exoPlayer.setTrackSelectionParameters(builder.build());
|
|
685
|
+
|
|
686
|
+
response.put("success", true);
|
|
687
|
+
response.put("message", "Audio track set successfully");
|
|
688
|
+
|
|
689
|
+
return response;
|
|
690
|
+
}
|
|
691
|
+
} catch (JSONException e) {
|
|
692
|
+
try {
|
|
693
|
+
response.put("success", false);
|
|
694
|
+
response.put("error", "Failed to check audio track: " + e.getMessage());
|
|
695
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
696
|
+
} catch (JSONException je) {
|
|
697
|
+
Log.e(TAG, "Error creating response JSON", je);
|
|
702
698
|
}
|
|
703
699
|
}
|
|
704
|
-
}
|
|
705
|
-
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
706
703
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
704
|
+
try {
|
|
705
|
+
response.put("success", false);
|
|
706
|
+
response.put("message", "Audio track not found " + trackId);
|
|
707
|
+
} catch (JSONException e) {
|
|
708
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
709
|
+
}
|
|
713
710
|
|
|
714
711
|
return response;
|
|
715
712
|
}
|
|
@@ -718,70 +715,66 @@ public class Player {
|
|
|
718
715
|
public JSONObject setSubtitleTrack(int trackId) {
|
|
719
716
|
JSONObject response = new JSONObject();
|
|
720
717
|
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
Log.e(TAG, "Error creating response JSON", e);
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
return response;
|
|
718
|
+
DefaultTrackSelector trackSelector = (DefaultTrackSelector) exoPlayer.getTrackSelector();
|
|
719
|
+
Tracks currentTracks = exoPlayer.getCurrentTracks();
|
|
720
|
+
|
|
721
|
+
if (currentTracks == null) {
|
|
722
|
+
try {
|
|
723
|
+
response.put("success", true);
|
|
724
|
+
response.put("message", "No current tracks found");
|
|
725
|
+
} catch (JSONException e) {
|
|
726
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
734
727
|
}
|
|
735
728
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
729
|
+
return response;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
for (Tracks.Group group : currentTracks.getGroups()) {
|
|
733
|
+
if (group.getType() == C.TRACK_TYPE_TEXT) {
|
|
734
|
+
for (int i = 0; i < group.length; i++) {
|
|
735
|
+
Format format = group.getTrackFormat(i);
|
|
736
|
+
int formatId = Integer.parseInt(format.id);
|
|
737
|
+
|
|
738
|
+
try {
|
|
739
|
+
if (trackId == formatId) {
|
|
740
|
+
// Found the target track - create selection override
|
|
741
|
+
DefaultTrackSelector.Parameters.Builder parametersBuilder = trackSelector.getParameters()
|
|
742
|
+
.buildUpon()
|
|
743
|
+
.setRendererDisabled(C.TRACK_TYPE_TEXT, false); // Enable text renderer
|
|
744
|
+
|
|
745
|
+
// Clear any existing text track overrides
|
|
746
|
+
parametersBuilder.clearOverridesOfType(C.TRACK_TYPE_TEXT);
|
|
747
|
+
|
|
748
|
+
// Set the new track selection override
|
|
749
|
+
parametersBuilder.addOverride(
|
|
750
|
+
new TrackSelectionOverride(group.getMediaTrackGroup(), ImmutableList.of(i))
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
trackSelector.setParameters(parametersBuilder.build());
|
|
759
754
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
Log.e(TAG, "Error creating response JSON", je);
|
|
772
|
-
}
|
|
755
|
+
response.put("success", true);
|
|
756
|
+
response.put("message", "Subtitle track set successfully");
|
|
757
|
+
return response;
|
|
758
|
+
}
|
|
759
|
+
} catch (JSONException e) {
|
|
760
|
+
try {
|
|
761
|
+
response.put("success", false);
|
|
762
|
+
response.put("error", "Failed to check subtitle track: " + e.getMessage());
|
|
763
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
764
|
+
} catch (JSONException je) {
|
|
765
|
+
Log.e(TAG, "Error creating response JSON", je);
|
|
773
766
|
}
|
|
774
767
|
}
|
|
775
768
|
}
|
|
776
769
|
}
|
|
770
|
+
}
|
|
777
771
|
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
772
|
+
try {
|
|
773
|
+
response.put("success", false);
|
|
774
|
+
response.put("message", "Subtitle track not found " + trackId);
|
|
775
|
+
} catch (JSONException e) {
|
|
776
|
+
Log.e(TAG, "Error creating response JSON", e);
|
|
777
|
+
}
|
|
785
778
|
|
|
786
779
|
return response;
|
|
787
780
|
}
|