15
15
import org .jellyfin .androidtv .R ;
16
16
import org .jellyfin .androidtv .data .compat .PlaybackException ;
17
17
import org .jellyfin .androidtv .data .compat .StreamInfo ;
18
- import org .jellyfin .androidtv .data .compat .SubtitleStreamInfo ;
19
18
import org .jellyfin .androidtv .data .compat .VideoOptions ;
20
19
import org .jellyfin .androidtv .data .model .DataRefreshService ;
21
20
import org .jellyfin .androidtv .preference .UserPreferences ;
28
27
import org .jellyfin .androidtv .util .TimeUtils ;
29
28
import org .jellyfin .androidtv .util .Utils ;
30
29
import org .jellyfin .androidtv .util .apiclient .ReportingHelper ;
31
- import org .jellyfin .androidtv .util .apiclient .StreamHelper ;
32
30
import org .jellyfin .androidtv .util .profile .ExoPlayerProfile ;
33
31
import org .jellyfin .androidtv .util .sdk .compat .JavaCompat ;
34
32
import org .jellyfin .apiclient .interaction .ApiClient ;
35
33
import org .jellyfin .apiclient .interaction .Response ;
36
34
import org .jellyfin .apiclient .model .dlna .DeviceProfile ;
37
- import org .jellyfin .apiclient .model .dlna .SubtitleDeliveryMethod ;
38
35
import org .jellyfin .apiclient .model .session .PlayMethod ;
39
36
import org .jellyfin .sdk .model .api .BaseItemDto ;
40
37
import org .jellyfin .sdk .model .api .BaseItemKind ;
@@ -70,20 +67,18 @@ public class PlaybackController implements PlaybackControllerNotifiable {
70
67
List <BaseItemDto > mItems ;
71
68
VideoManager mVideoManager ;
72
69
int mCurrentIndex ;
73
- private long mCurrentPosition = 0 ;
70
+ protected long mCurrentPosition = 0 ;
74
71
private PlaybackState mPlaybackState = PlaybackState .IDLE ;
75
72
76
73
private StreamInfo mCurrentStreamInfo ;
77
- private List <SubtitleStreamInfo > mSubtitleStreams ;
78
74
79
75
@ Nullable
80
76
private CustomPlaybackOverlayFragment mFragment ;
81
77
private Boolean spinnerOff = false ;
82
78
83
- private VideoOptions mCurrentOptions ;
84
- private int mDefaultSubIndex = -1 ;
79
+ protected VideoOptions mCurrentOptions ;
85
80
private int mDefaultAudioIndex = -1 ;
86
- private boolean burningSubs = false ;
81
+ protected boolean burningSubs = false ;
87
82
private float mRequestedPlaybackSpeed = -1.0f ;
88
83
89
84
private Runnable mReportLoop ;
@@ -211,18 +206,6 @@ public int getSubtitleStreamIndex() {
211
206
return (mCurrentOptions != null && mCurrentOptions .getSubtitleStreamIndex () != null ) ? mCurrentOptions .getSubtitleStreamIndex () : -1 ;
212
207
}
213
208
214
- public List <SubtitleStreamInfo > getSubtitleStreams () {
215
- return mSubtitleStreams ;
216
- }
217
-
218
- public SubtitleStreamInfo getSubtitleStreamInfo (int index ) {
219
- for (SubtitleStreamInfo info : mSubtitleStreams ) {
220
- if (info .getIndex () == index ) return info ;
221
- }
222
-
223
- return null ;
224
- }
225
-
226
209
public boolean isTranscoding () {
227
210
// use or here so that true is the default since
228
211
// this method is used to exclude features that may break unless we are sure playback is direct
@@ -401,7 +384,7 @@ public void play(long position) {
401
384
play (position , null );
402
385
}
403
386
404
- private void play (long position , @ Nullable Integer forcedSubtitleIndex ) {
387
+ protected void play (long position , @ Nullable Integer forcedSubtitleIndex ) {
405
388
Timber .i ("Play called from state: %s with pos: %d and sub index: %d" , mPlaybackState , position , forcedSubtitleIndex );
406
389
407
390
if (mFragment == null ) {
@@ -607,22 +590,10 @@ private void startItem(BaseItemDto item, long position, StreamInfo response) {
607
590
mCurrentOptions .setMediaSourceId (response .getMediaSource ().getId ());
608
591
609
592
// get subtitle info
610
- mSubtitleStreams = response .getSubtitleProfiles (false , apiClient .getValue ().getApiUrl (), apiClient .getValue ().getAccessToken ());
611
- mDefaultSubIndex = response .getMediaSource ().getDefaultSubtitleStreamIndex () != null ? response .getMediaSource ().getDefaultSubtitleStreamIndex () : mDefaultSubIndex ;
593
+ mCurrentOptions .setSubtitleStreamIndex (response .getMediaSource ().getDefaultSubtitleStreamIndex () != null ? response .getMediaSource ().getDefaultSubtitleStreamIndex () : null );
612
594
setDefaultAudioIndex (response );
613
595
Timber .d ("default audio index set to %s remote default %s" , mDefaultAudioIndex , response .getMediaSource ().getDefaultAudioStreamIndex ());
614
- Timber .d ("default sub index set to %s remote default %s" , mDefaultSubIndex , response .getMediaSource ().getDefaultSubtitleStreamIndex ());
615
-
616
- // if burning in, set the subtitle index and the burningSubs flag so that onPrepared and switchSubtitleStream will know that we already have subtitles enabled
617
- burningSubs = false ;
618
- if (mCurrentStreamInfo .getPlayMethod () == PlayMethod .Transcode && getSubtitleStreamInfo (mDefaultSubIndex ) != null &&
619
- getSubtitleStreamInfo (mDefaultSubIndex ).getDeliveryMethod () == SubtitleDeliveryMethod .Encode ) {
620
- mCurrentOptions .setSubtitleStreamIndex (mDefaultSubIndex );
621
- Timber .d ("stream started with burnt in subs" );
622
- burningSubs = true ;
623
- } else {
624
- mCurrentOptions .setSubtitleStreamIndex (null );
625
- }
596
+ Timber .d ("default sub index set to %s remote default %s" , mCurrentOptions .getSubtitleStreamIndex (), response .getMediaSource ().getDefaultSubtitleStreamIndex ());
626
597
627
598
Long mbPos = position * 10000 ;
628
599
@@ -638,7 +609,7 @@ private void startItem(BaseItemDto item, long position, StreamInfo response) {
638
609
if (mFragment != null ) mFragment .updateDisplay ();
639
610
640
611
if (mVideoManager != null ) {
641
- mVideoManager .setVideoPath ( response . getMediaUrl () );
612
+ mVideoManager .setMediaStreamInfo ( api . getValue (), response );
642
613
}
643
614
644
615
PlaybackControllerHelperKt .applyMediaSegments (this , item , () -> {
@@ -752,67 +723,6 @@ public void switchAudioStream(int index) {
752
723
}
753
724
}
754
725
755
-
756
- public void switchSubtitleStream (int index ) {
757
- if (!hasInitializedVideoManager ())
758
- return ;
759
- // get current timestamp first
760
- refreshCurrentPosition ();
761
- Timber .d ("Setting subtitle index to: %d" , index );
762
-
763
- // clear the default in case there's an error loading the subtitles
764
- mDefaultSubIndex = -1 ;
765
-
766
- // handle setting subtitles as disabled
767
- // restart playback if turning off burnt-in subtitles
768
- if (index < 0 ) {
769
- mCurrentOptions .setSubtitleStreamIndex (-1 );
770
- if (burningSubs ) {
771
- stop ();
772
- play (mCurrentPosition , -1 );
773
- }
774
- return ;
775
- }
776
-
777
- org .jellyfin .sdk .model .api .MediaStream stream = StreamHelper .getMediaStream (getCurrentMediaSource (), index );
778
- if (stream == null ) {
779
- if (mFragment != null )
780
- Utils .showToast (mFragment .getContext (), mFragment .getString (R .string .subtitle_error ));
781
- return ;
782
- }
783
- SubtitleStreamInfo streamInfo = getSubtitleStreamInfo (index );
784
- if (streamInfo == null ) {
785
- if (mFragment != null )
786
- Utils .showToast (mFragment .getContext (), mFragment .getString (R .string .msg_unable_load_subs ));
787
- return ;
788
- }
789
-
790
- // handle switching on or between burnt-in subtitles, or switching to non-burnt subtitles
791
- // if switching from burnt-in subtitles to another type, playback still needs to be restarted
792
- if (burningSubs || streamInfo .getDeliveryMethod () == SubtitleDeliveryMethod .Encode ) {
793
- stop ();
794
- if (mFragment != null && streamInfo .getDeliveryMethod () == SubtitleDeliveryMethod .Encode )
795
- Utils .showToast (mFragment .getContext (), mFragment .getString (R .string .msg_burn_sub_warning ));
796
- play (mCurrentPosition , index );
797
- return ;
798
- }
799
-
800
- // when burnt-in subtitles are selected, mCurrentOptions SubtitleStreamIndex is set in startItem() as soon as playback starts
801
- // otherwise mCurrentOptions SubtitleStreamIndex is kept null until now so we knew subtitles needed to be enabled but weren't already
802
-
803
- if (streamInfo .getDeliveryMethod () == SubtitleDeliveryMethod .Embed ) {
804
- if (!mVideoManager .setExoPlayerTrack (index , MediaStreamType .SUBTITLE , getCurrentlyPlayingItem ().getMediaStreams ())) {
805
- // error selecting internal subs
806
- if (mFragment != null )
807
- Utils .showToast (mFragment .getContext (), mFragment .getString (R .string .msg_unable_load_subs ));
808
- } else {
809
- mCurrentOptions .setSubtitleStreamIndex (index );
810
- mDefaultSubIndex = index ;
811
-
812
- }
813
- }
814
- }
815
-
816
726
public void pause () {
817
727
Timber .d ("pause called at %s" , mCurrentPosition );
818
728
// if playback is paused and the seekbar is scrubbed, it will call pause even if already paused
@@ -887,7 +797,6 @@ private void resetPlayerErrors() {
887
797
}
888
798
889
799
private void clearPlaybackSessionOptions () {
890
- mDefaultSubIndex = -1 ;
891
800
mDefaultAudioIndex = -1 ;
892
801
mSeekPosition = -1 ;
893
802
finishedInitialSeek = false ;
@@ -980,7 +889,7 @@ public void seek(long pos, boolean skipToNext) {
980
889
public void onResponse (StreamInfo response ) {
981
890
mCurrentStreamInfo = response ;
982
891
if (mVideoManager != null ) {
983
- mVideoManager .setVideoPath ( response . getMediaUrl () );
892
+ mVideoManager .setMediaStreamInfo ( api . getValue (), response );
984
893
mVideoManager .start ();
985
894
}
986
895
}
@@ -1186,16 +1095,13 @@ public void onPrepared() {
1186
1095
if (mPlaybackState == PlaybackState .PAUSED ) {
1187
1096
mPlaybackState = PlaybackState .PLAYING ;
1188
1097
} else {
1189
- // select or disable subtitles
1190
- Integer currentSubtitleIndex = mCurrentOptions .getSubtitleStreamIndex ();
1191
- if (mDefaultSubIndex >= 0 && currentSubtitleIndex != null && currentSubtitleIndex == mDefaultSubIndex ) {
1192
- Timber .i ("subtitle stream %s is already selected" , mDefaultSubIndex );
1193
- } else {
1194
- if (mDefaultSubIndex < 0 )
1195
- Timber .i ("Turning off subs" );
1196
- else
1197
- Timber .i ("Enabling default sub stream: %d" , mDefaultSubIndex );
1198
- switchSubtitleStream (mDefaultSubIndex );
1098
+ if (!burningSubs ) {
1099
+ // Make sure the requested subtitles are enabled when external/embedded
1100
+ Integer currentSubtitleIndex = mCurrentOptions .getSubtitleStreamIndex ();
1101
+
1102
+ if (currentSubtitleIndex != null && currentSubtitleIndex != -1 ) {
1103
+ PlaybackControllerHelperKt .setSubtitleIndex (this , currentSubtitleIndex , true );
1104
+ }
1199
1105
}
1200
1106
1201
1107
// select an audio track
0 commit comments