Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the support for SRT & VTT subtitle format. #118

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ public class Body {

@Expose
public List<File> files = new ArrayList<>();

@Expose
public List<SubTitle> subtitles = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.zype.fire.api.Model;

import com.google.gson.annotations.Expose;

public class SubTitle {
@Expose
public String file;

@Expose
public String label;
}
4 changes: 2 additions & 2 deletions Application/app/version.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#Sat Jun 26 10:24:21 IST 2021
VERSION_CODE=1310
#Fri Jul 30 11:04:45 IST 2021
VERSION_CODE=1311
adb=u
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import android.os.Handler;
import android.provider.Settings;
import androidx.annotation.Nullable;

import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
Expand All @@ -48,6 +50,8 @@
import com.google.android.exoplayer2.Timeline;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.ExtractorMediaSource;
import com.google.android.exoplayer2.source.MergingMediaSource;
import com.google.android.exoplayer2.source.SingleSampleMediaSource;
import com.google.android.exoplayer2.source.TrackGroup;
import com.google.android.exoplayer2.source.TrackGroupArray;
import com.google.android.exoplayer2.source.dash.DashMediaSource;
Expand All @@ -69,6 +73,7 @@
import com.google.android.exoplayer2.upstream.HttpDataSource;
import com.google.android.exoplayer2.upstream.TransferListener;
import com.google.android.exoplayer2.util.EventLogger;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
import com.google.android.exoplayer2.video.VideoListener;

Expand Down Expand Up @@ -135,7 +140,7 @@ public class ExoPlayer2MediaPlayer implements UAMP, SurfaceHolder.Callback, Even
private Set<OnStateChangeListener> mStateListeners;
private Set<OnCuesListener> mCuesListeners;
private Set<OnInfoListener> mInfoListeners;

private String ccUrl="";
/**
* Static bandwidth meter so that we get a universal view from all transfers.
*/
Expand Down Expand Up @@ -190,6 +195,14 @@ public boolean canRenderAds() {
return false;
}

/**
* {@inheritDoc}
*/
@Override
public void updateSubTitleUrl(String url) {
ccUrl = url;
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -264,7 +277,8 @@ public void init(Context context, FrameLayout frameLayout, Bundle extras) {
mTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
mTrackSelector = new DefaultTrackSelector(mTrackSelectionFactory);
eventLogger = new EventLogger(mTrackSelector);

mTrackSelector.setParameters(new
DefaultTrackSelector.ParametersBuilder().setPreferredAudioLanguage("eng").build());
mPlayer = ExoPlayerFactory.newSimpleInstance(mContext, mTrackSelector);
mPlayer.addListener(eventLogger);
mPlayer.addListener(new PlayerEventListener());
Expand Down Expand Up @@ -641,7 +655,31 @@ public void open(ContentParameters contentParameters) {

setPlayerState(PlayerState.OPENING);
if (mediaSource != null) {
mCurrentMediaSource = mediaSource;
if (!TextUtils.isEmpty(ccUrl) && (ccUrl.contains(".srt") || ccUrl.contains(".vtt"))) {
MediaSource[] mediaSources = new MediaSource[2]; //The Size must change depending on the Uris
mediaSources[0] = mediaSource; // uri

Uri subtitleUri = Uri.parse(ccUrl);
Format textFormat;
if (ccUrl.contains(".srt")){
textFormat= Format.createTextSampleFormat(null, MimeTypes.APPLICATION_SUBRIP, Format.NO_VALUE, "en", null);
}else{
textFormat = Format.createTextSampleFormat(
null,
MimeTypes.TEXT_VTT,
C.SELECTION_FLAG_DEFAULT,
null
);
}
//Add subtitles
SingleSampleMediaSource subtitleSource = new SingleSampleMediaSource(subtitleUri, mDataSourceFactory,
textFormat,
C.TIME_UNSET);
mediaSources[1] = subtitleSource;
mCurrentMediaSource = new MergingMediaSource(mediaSources);
} else {
mCurrentMediaSource = mediaSource;
}
setPlayerState(PlayerState.OPENED);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ public void modifyClosedCaptionState(boolean state) {
mPlayer.enableTextTrack(TrackType.CLOSED_CAPTION, state);
}
else {
mPlayer.enableTextTrack(TrackType.SUBTITLE, state);
// mPlayer.enableTextTrack(TrackType.SUBTITLE, state);
}
// /* Zype, Evgeny Cherkasov */
// int ccTrackIndex = -1;
Expand Down Expand Up @@ -2308,6 +2308,10 @@ private Content updateContentWithPlayerData(Content content, PlayerData playerDa
// Url
String url = playerData.body.files.get(0).url;
content.setUrl(url);
if (playerData.body.subtitles != null && playerData.body.subtitles.size() > 0) {
String subTitle = playerData.body.subtitles.get(0).file;
mPlayer.updateSubTitleUrl(subTitle);
}
content.setExtraValue(Content.EXTRA_VIDEO_URL, content.getUrl());
checkIsAudio(url);
// Ads
Expand Down
3 changes: 3 additions & 0 deletions UAMP/src/main/java/com/amazon/android/uamp/UAMP.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ public interface UAMP extends AMZNMediaPlayer {

/* Zype, Evgeny Cherkasov */
void updateSurfaceView();


void updateSubTitleUrl(String ccUrl);
}