forked from recloudstream/cloudstream
		
	minor fix
This commit is contained in:
		
							parent
							
								
									3f1e398ae8
								
							
						
					
					
						commit
						48c786a5b8
					
				
					 3 changed files with 51 additions and 30 deletions
				
			
		|  | @ -11,6 +11,7 @@ import com.google.android.exoplayer2.extractor.ExtractorsFactory | ||||||
| import com.google.android.exoplayer2.source.DefaultMediaSourceFactory | import com.google.android.exoplayer2.source.DefaultMediaSourceFactory | ||||||
| import com.google.android.exoplayer2.source.MergingMediaSource | import com.google.android.exoplayer2.source.MergingMediaSource | ||||||
| import com.google.android.exoplayer2.source.ProgressiveMediaSource | import com.google.android.exoplayer2.source.ProgressiveMediaSource | ||||||
|  | import com.google.android.exoplayer2.text.SubtitleDecoderFactory | ||||||
| import com.google.android.exoplayer2.text.SubtitleExtractor | import com.google.android.exoplayer2.text.SubtitleExtractor | ||||||
| import com.google.android.exoplayer2.trackselection.DefaultTrackSelector | import com.google.android.exoplayer2.trackselection.DefaultTrackSelector | ||||||
| import com.google.android.exoplayer2.trackselection.TrackSelector | import com.google.android.exoplayer2.trackselection.TrackSelector | ||||||
|  | @ -598,11 +599,26 @@ class CS3IPlayer : IPlayer { | ||||||
|                 .setSelectionFlags(C.SELECTION_FLAG_DEFAULT) |                 .setSelectionFlags(C.SELECTION_FLAG_DEFAULT) | ||||||
|                 .build() |                 .build() | ||||||
| 
 | 
 | ||||||
|  |             val ownFactory = CustomSubtitleDecoderFactory() | ||||||
|             val extractorFactory = ExtractorsFactory { |             val extractorFactory = ExtractorsFactory { | ||||||
|                 arrayOf( |                 arrayOf( | ||||||
|  |                     if (ownFactory.supportsFormat(format)) { | ||||||
|                         SubtitleExtractor( |                         SubtitleExtractor( | ||||||
|                         CustomSubtitleDecoderFactory().createDecoder(format), format |                             ownFactory.createDecoder(format), format | ||||||
|                         ) |                         ) | ||||||
|  |                     } else { | ||||||
|  |                         if (SubtitleDecoderFactory.DEFAULT.supportsFormat(format)) { | ||||||
|  |                             SubtitleExtractor( | ||||||
|  |                                 SubtitleDecoderFactory.DEFAULT.createDecoder(format), format | ||||||
|  |                             ) | ||||||
|  |                         } else { | ||||||
|  |                             // ye we guess if not found instead of using UnknownSubtitlesExtractor, | ||||||
|  |                             // this way you can hopefully load a .txt file that is an srt and it will work | ||||||
|  |                             SubtitleExtractor( | ||||||
|  |                                 ownFactory.createDecoder(format), format | ||||||
|  |                             ) | ||||||
|  |                         } | ||||||
|  |                     } | ||||||
|                 ) |                 ) | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -11,6 +11,7 @@ import com.google.android.exoplayer2.text.subrip.SubripDecoder | ||||||
| import com.google.android.exoplayer2.text.ttml.TtmlDecoder | import com.google.android.exoplayer2.text.ttml.TtmlDecoder | ||||||
| import com.google.android.exoplayer2.text.webvtt.WebvttDecoder | import com.google.android.exoplayer2.text.webvtt.WebvttDecoder | ||||||
| import com.google.android.exoplayer2.util.MimeTypes | import com.google.android.exoplayer2.util.MimeTypes | ||||||
|  | import com.lagradost.cloudstream3.mvvm.logError | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class CustomDecoder : SubtitleDecoder { | class CustomDecoder : SubtitleDecoder { | ||||||
|  | @ -18,7 +19,7 @@ class CustomDecoder : SubtitleDecoder { | ||||||
|         private const val TAG = "CustomDecoder" |         private const val TAG = "CustomDecoder" | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     var realDecoder: SubtitleDecoder? = null |     private var realDecoder: SubtitleDecoder? = null | ||||||
| 
 | 
 | ||||||
|     override fun getName(): String { |     override fun getName(): String { | ||||||
|         return realDecoder?.name ?: this::class.java.name |         return realDecoder?.name ?: this::class.java.name | ||||||
|  | @ -31,9 +32,10 @@ class CustomDecoder : SubtitleDecoder { | ||||||
| 
 | 
 | ||||||
|     override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) { |     override fun queueInputBuffer(inputBuffer: SubtitleInputBuffer) { | ||||||
|         Log.i(TAG, "queueInputBuffer") |         Log.i(TAG, "queueInputBuffer") | ||||||
| 
 |         try { | ||||||
|             if (realDecoder == null) { |             if (realDecoder == null) { | ||||||
|                 inputBuffer.data?.let { data -> |                 inputBuffer.data?.let { data -> | ||||||
|  |                     // this way we read the subtitle file and decide what decoder to use instead of relying on mimetype | ||||||
| 
 | 
 | ||||||
|                     val pos = data.position() |                     val pos = data.position() | ||||||
|                     data.position(0) |                     data.position(0) | ||||||
|  | @ -62,6 +64,9 @@ class CustomDecoder : SubtitleDecoder { | ||||||
|             } else { |             } else { | ||||||
|                 realDecoder?.dequeueInputBuffer() |                 realDecoder?.dequeueInputBuffer() | ||||||
|             } |             } | ||||||
|  |         } catch (e: Exception) { | ||||||
|  |             logError(e) | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     override fun dequeueOutputBuffer(): SubtitleOutputBuffer? { |     override fun dequeueOutputBuffer(): SubtitleOutputBuffer? { | ||||||
|  |  | ||||||
|  | @ -103,9 +103,9 @@ class GeneratorPlayer : FullScreenPlayer() { | ||||||
|             val (linkData, _) = it |             val (linkData, _) = it | ||||||
|             var quality = linkData?.quality ?: Qualities.Unknown.value |             var quality = linkData?.quality ?: Qualities.Unknown.value | ||||||
| 
 | 
 | ||||||
|             // we set all qualities above current max as max -1 |             // we set all qualities above current max as reverse | ||||||
|             if (useQualitySettings && quality > currentPrefQuality) { |             if (useQualitySettings && quality > currentPrefQuality) { | ||||||
|                 quality = currentPrefQuality - 1 |                 quality = currentPrefQuality - quality - 1 | ||||||
|             } |             } | ||||||
|             // negative because we want to sort highest quality first |             // negative because we want to sort highest quality first | ||||||
|             -(quality) |             -(quality) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue