Chore/refactor in api folder (#3285)
* feat: add prop to allow controlling of debug log level * fix: move props parsing to safeGetters * chore: fix typing * chore: fix types and lintter * chore: move file VideoEventEmitter * fix: make VideoEventEmitter player agnostic And create a dedicated API data for that * chore: move generic file in API folder --------- Co-authored-by: olivier <olivier.bouillet@ifeelsmart.com>
This commit is contained in:
@@ -19,6 +19,8 @@ import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.brentvatne.common.API.ResizeMode;
|
||||
|
||||
/**
|
||||
* A {@link FrameLayout} that resizes itself to match a specified aspect ratio.
|
||||
*/
|
||||
|
@@ -11,6 +11,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.brentvatne.common.API.ResizeMode;
|
||||
import com.brentvatne.common.API.SubtitleStyle;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
|
@@ -26,12 +26,13 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.WorkerThread;
|
||||
import androidx.activity.OnBackPressedCallback;
|
||||
|
||||
import com.brentvatne.common.API.ResizeMode;
|
||||
import com.brentvatne.common.API.SubtitleStyle;
|
||||
import com.brentvatne.common.API.TimedMetadata;
|
||||
import com.brentvatne.common.Track;
|
||||
import com.brentvatne.common.VideoTrack;
|
||||
import com.brentvatne.common.API.Track;
|
||||
import com.brentvatne.common.API.VideoTrack;
|
||||
import com.brentvatne.common.react.VideoEventEmitter;
|
||||
import com.brentvatne.common.toolbox.DebugLog;
|
||||
import com.brentvatne.exoplayer.AudioOutput;
|
||||
import com.brentvatne.react.R;
|
||||
import com.brentvatne.receiver.AudioBecomingNoisyReceiver;
|
||||
import com.brentvatne.receiver.BecomingNoisyListener;
|
||||
@@ -1209,18 +1210,23 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
for (int i = 0; i < groups.length; ++i) {
|
||||
TrackGroup group = groups.get(i);
|
||||
Format format = group.getFormat(0);
|
||||
Track audioTrack = new Track();
|
||||
audioTrack.m_index = i;
|
||||
audioTrack.m_title = format.id != null ? format.id : "";
|
||||
audioTrack.m_mimeType = format.sampleMimeType;
|
||||
audioTrack.m_language = format.language != null ? format.language : "";
|
||||
audioTrack.m_bitrate = format.bitrate == Format.NO_VALUE ? 0 : format.bitrate;
|
||||
audioTrack.m_isSelected = isTrackSelected(selection, group, 0 );
|
||||
Track audioTrack = exoplayerTrackToGenericTrack(format, i, selection, group);
|
||||
audioTrack.setBitrate(format.bitrate == Format.NO_VALUE ? 0 : format.bitrate);
|
||||
audioTracks.add(audioTrack);
|
||||
}
|
||||
return audioTracks;
|
||||
}
|
||||
|
||||
private VideoTrack exoplayerVideoTrackToGenericVideoTrack(Format format, int trackIndex) {
|
||||
VideoTrack videoTrack = new VideoTrack();
|
||||
videoTrack.setWidth(format.width == Format.NO_VALUE ? 0 : format.width);
|
||||
videoTrack.setHeight(format.height == Format.NO_VALUE ? 0 : format.height);
|
||||
videoTrack.setBitrate(format.bitrate == Format.NO_VALUE ? 0 : format.bitrate);
|
||||
if (format.codecs != null) videoTrack.setCodecs(format.codecs);
|
||||
videoTrack.setTrackId(format.id == null ? String.valueOf(trackIndex) : format.id);;
|
||||
return videoTrack;
|
||||
}
|
||||
|
||||
private ArrayList<VideoTrack> getVideoTrackInfo() {
|
||||
ArrayList<VideoTrack> videoTracks = new ArrayList<>();
|
||||
if (trackSelector == null) {
|
||||
@@ -1240,12 +1246,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
|
||||
Format format = group.getFormat(trackIndex);
|
||||
if (isFormatSupported(format)) {
|
||||
VideoTrack videoTrack = new VideoTrack();
|
||||
videoTrack.m_width = format.width == Format.NO_VALUE ? 0 : format.width;
|
||||
videoTrack.m_height = format.height == Format.NO_VALUE ? 0 : format.height;
|
||||
videoTrack.m_bitrate = format.bitrate == Format.NO_VALUE ? 0 : format.bitrate;
|
||||
videoTrack.m_codecs = format.codecs != null ? format.codecs : "";
|
||||
videoTrack.m_trackId = format.id == null ? String.valueOf(trackIndex) : format.id;
|
||||
VideoTrack videoTrack = exoplayerVideoTrackToGenericVideoTrack(format, trackIndex);
|
||||
videoTracks.add(videoTrack);
|
||||
}
|
||||
}
|
||||
@@ -1291,12 +1292,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
break;
|
||||
}
|
||||
hasFoundContentPeriod = true;
|
||||
VideoTrack videoTrack = new VideoTrack();
|
||||
videoTrack.m_width = format.width == Format.NO_VALUE ? 0 : format.width;
|
||||
videoTrack.m_height = format.height == Format.NO_VALUE ? 0 : format.height;
|
||||
videoTrack.m_bitrate = format.bitrate == Format.NO_VALUE ? 0 : format.bitrate;
|
||||
videoTrack.m_codecs = format.codecs != null ? format.codecs : "";
|
||||
videoTrack.m_trackId = format.id == null ? String.valueOf(representationIndex) : format.id;
|
||||
VideoTrack videoTrack = exoplayerVideoTrackToGenericVideoTrack(format, representationIndex);
|
||||
videoTracks.add(videoTrack);
|
||||
}
|
||||
}
|
||||
@@ -1326,6 +1322,17 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private Track exoplayerTrackToGenericTrack(Format format, int trackIndex, TrackSelection selection, TrackGroup group) {
|
||||
Track track = new Track();
|
||||
track.setIndex(trackIndex);
|
||||
if (format.sampleMimeType != null) track.setMimeType(format.sampleMimeType);
|
||||
if (format.language != null) track.setLanguage(format.language);
|
||||
if (format.id != null) track.setTitle(format.id);
|
||||
track.setSelected(isTrackSelected(selection, group, 0));
|
||||
return track;
|
||||
}
|
||||
|
||||
private ArrayList<Track> getTextTrackInfo() {
|
||||
ArrayList<Track> textTracks = new ArrayList<>();
|
||||
if (trackSelector == null) {
|
||||
@@ -1343,13 +1350,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
for (int i = 0; i < groups.length; ++i) {
|
||||
TrackGroup group = groups.get(i);
|
||||
Format format = group.getFormat(0);
|
||||
|
||||
Track textTrack = new Track();
|
||||
textTrack.m_index = i;
|
||||
textTrack.m_title = format.id != null ? format.id : "";
|
||||
textTrack.m_mimeType = format.sampleMimeType;
|
||||
textTrack.m_language = format.language != null ? format.language : "";
|
||||
textTrack.m_isSelected = isTrackSelected(selection, group, 0 );
|
||||
Track textTrack = exoplayerTrackToGenericTrack(format, i, selection, group);
|
||||
textTracks.add(textTrack);
|
||||
}
|
||||
return textTracks;
|
||||
@@ -1494,19 +1495,11 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
TextInformationFrame txxxFrame = (TextInformationFrame) frame;
|
||||
value = txxxFrame.value;
|
||||
}
|
||||
|
||||
String identifier = frame.id;
|
||||
|
||||
TimedMetadata timedMetadata = new TimedMetadata();
|
||||
timedMetadata.m_Identifier = identifier;
|
||||
timedMetadata.m_Value = value;
|
||||
|
||||
TimedMetadata timedMetadata = new TimedMetadata(frame.id, value);
|
||||
metadataArray.add(timedMetadata);
|
||||
} else if (entry instanceof EventMessage) {
|
||||
EventMessage eventMessage = (EventMessage) entry;
|
||||
TimedMetadata timedMetadata = new TimedMetadata();
|
||||
timedMetadata.m_Identifier = eventMessage.schemeIdUri;
|
||||
timedMetadata.m_Value = eventMessage.value;
|
||||
TimedMetadata timedMetadata = new TimedMetadata(eventMessage.schemeIdUri, eventMessage.value);
|
||||
metadataArray.add(timedMetadata);
|
||||
} else {
|
||||
DebugLog.d(TAG, "unhandled metadata " + entry.toString());
|
||||
|
@@ -6,10 +6,11 @@ import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.brentvatne.common.API.ResizeMode;
|
||||
import com.brentvatne.common.API.SubtitleStyle;
|
||||
import com.brentvatne.common.react.VideoEventEmitter;
|
||||
import com.brentvatne.common.toolbox.DebugLog;
|
||||
import com.brentvatne.common.toolbox.ReactBridgeUtils;
|
||||
import com.brentvatne.exoplayer.AudioOutput;
|
||||
import com.facebook.react.bridge.Dynamic;
|
||||
import com.facebook.react.bridge.ReadableArray;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
@@ -1,63 +0,0 @@
|
||||
package com.brentvatne.exoplayer;
|
||||
|
||||
import androidx.annotation.IntDef;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.SOURCE;
|
||||
|
||||
class ResizeMode {
|
||||
|
||||
/**
|
||||
* Either the width or height is decreased to obtain the desired aspect ratio.
|
||||
*/
|
||||
static final int RESIZE_MODE_FIT = 0;
|
||||
/**
|
||||
* The width is fixed and the height is increased or decreased to obtain the desired aspect ratio.
|
||||
*/
|
||||
static final int RESIZE_MODE_FIXED_WIDTH = 1;
|
||||
/**
|
||||
* The height is fixed and the width is increased or decreased to obtain the desired aspect ratio.
|
||||
*/
|
||||
static final int RESIZE_MODE_FIXED_HEIGHT = 2;
|
||||
/**
|
||||
* The height and the width is increased or decreased to fit the size of the view.
|
||||
*/
|
||||
static final int RESIZE_MODE_FILL = 3;
|
||||
/**
|
||||
* Keeps the aspect ratio but takes up the view's size.
|
||||
*/
|
||||
static final int RESIZE_MODE_CENTER_CROP = 4;
|
||||
|
||||
@Retention(SOURCE)
|
||||
@IntDef({
|
||||
RESIZE_MODE_FIT,
|
||||
RESIZE_MODE_FIXED_WIDTH,
|
||||
RESIZE_MODE_FIXED_HEIGHT,
|
||||
RESIZE_MODE_FILL,
|
||||
RESIZE_MODE_CENTER_CROP
|
||||
})
|
||||
public @interface Mode {
|
||||
}
|
||||
|
||||
@ResizeMode.Mode static int toResizeMode(int ordinal) {
|
||||
switch (ordinal) {
|
||||
case ResizeMode.RESIZE_MODE_FIXED_WIDTH:
|
||||
return ResizeMode.RESIZE_MODE_FIXED_WIDTH;
|
||||
|
||||
case ResizeMode.RESIZE_MODE_FIXED_HEIGHT:
|
||||
return ResizeMode.RESIZE_MODE_FIXED_HEIGHT;
|
||||
|
||||
case ResizeMode.RESIZE_MODE_FILL:
|
||||
return ResizeMode.RESIZE_MODE_FILL;
|
||||
|
||||
case ResizeMode.RESIZE_MODE_CENTER_CROP:
|
||||
return ResizeMode.RESIZE_MODE_CENTER_CROP;
|
||||
|
||||
case ResizeMode.RESIZE_MODE_FIT:
|
||||
default:
|
||||
return ResizeMode.RESIZE_MODE_FIT;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package com.brentvatne.exoplayer;
|
||||
import com.brentvatne.ReactBridgeUtils;
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
/**
|
||||
* Helper file to parse SubtitleStyle prop and build a dedicated class
|
||||
*/
|
||||
public class SubtitleStyle {
|
||||
private static final String PROP_FONT_SIZE_TRACK = "fontSize";
|
||||
private static final String PROP_PADDING_BOTTOM = "paddingBottom";
|
||||
private static final String PROP_PADDING_TOP = "paddingTop";
|
||||
private static final String PROP_PADDING_LEFT = "paddingLeft";
|
||||
private static final String PROP_PADDING_RIGHT = "paddingRight";
|
||||
|
||||
private int fontSize = -1;
|
||||
private int paddingLeft = 0;
|
||||
private int paddingRight = 0;
|
||||
private int paddingTop = 0;
|
||||
private int paddingBottom = 0;
|
||||
|
||||
private SubtitleStyle() {}
|
||||
|
||||
int getFontSize() {return fontSize;}
|
||||
int getPaddingBottom() {return paddingBottom;}
|
||||
int getPaddingTop() {return paddingTop;}
|
||||
int getPaddingLeft() {return paddingLeft;}
|
||||
int getPaddingRight() {return paddingRight;}
|
||||
|
||||
public static SubtitleStyle parse(ReadableMap src) {
|
||||
SubtitleStyle subtitleStyle = new SubtitleStyle();
|
||||
subtitleStyle.fontSize = ReactBridgeUtils.safeGetInt(src, PROP_FONT_SIZE_TRACK, -1);
|
||||
subtitleStyle.paddingBottom = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_BOTTOM, 0);
|
||||
subtitleStyle.paddingTop = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_TOP, 0);
|
||||
subtitleStyle.paddingLeft = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_LEFT, 0);
|
||||
subtitleStyle.paddingRight = ReactBridgeUtils.safeGetInt(src, PROP_PADDING_RIGHT, 0);
|
||||
return subtitleStyle;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user