This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| implementation("androidx.media3:media3-exoplayer:1.4.1") | |
| implementation("androidx.media3:media3-ui:1.4.1") | |
| implementation("androidx.media3:media3-exoplayer-hls:1.4.1") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun setupPlayer( | |
| playbackLooper: Looper, | |
| loadControl: LoadControl, // Use same as used in setting up Preload Manager | |
| renderersFactory: RenderersFactory, // Use same as used in setting up Preload Manager | |
| bandwidthMeter: BandwidthMeter, // Use same as used in setting up Preload Manager | |
| ) { | |
| player = ExoPlayer.Builder(this) | |
| .setPlaybackLooper(playbackLooper) | |
| .setLoadControl(loadControl) | |
| .setRenderersFactory(renderersFactory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @UnstableApi | |
| class DefaultPreloadControl : TargetPreloadStatusControl<Int> { | |
| override fun getTargetPreloadStatus(rankingData: Int): DefaultPreloadManager.Status? { | |
| return DefaultPreloadManager.Status(STAGE_LOADED_TO_POSITION_MS, 500) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun setupPreloadManager() { | |
| val LOAD_CONTROL_MIN_BUFFER_MS = 5_000 | |
| val LOAD_CONTROL_MAX_BUFFER_MS = 20_000 | |
| val LOAD_CONTROL_BUFFER_FOR_PLAYBACK_MS = 500 | |
| val playbackThread: HandlerThread = | |
| HandlerThread("playback-thread", android.os.Process.THREAD_PRIORITY_AUDIO) | |
| playbackThread.start() | |
| val loadControl = DefaultLoadControl.Builder() | |
| .setBufferDurationsMs( | |
| LOAD_CONTROL_MIN_BUFFER_MS, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| implementation "androidx.media3:media3-transformer:1.1.1" | |
| implementation "androidx.media3:media3-effect:1.1.1" | |
| implementation "androidx.media3:media3-common:1.1.1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private fun convertToGrayScale() { | |
| val effect = arrayListOf<Effect>() | |
| effect.add(RgbFilter.createGrayscaleFilter()) | |
| val transformer = with(Transformer.Builder(this)) { | |
| addListener(object : Transformer.Listener { | |
| override fun onCompleted(composition: Composition, exportResult: ExportResult) { | |
| //Play the video from the path you specified below | |
| } | |
| override fun onError( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val effect = arrayListOf<Effect>() | |
| effect.add(RgbFilter.createGrayscaleFilter()) | |
| effect.add(MatrixTransformationFactory.createZoomInTransition()) | |
| effect.add(ScaleAndRotateTransformation.Builder().setRotationDegrees(90F).build()) | |
| val transformer = with(Transformer.Builder(this)) { | |
| addListener(object : Transformer.Listener { | |
| override fun onCompleted(composition: Composition, exportResult: ExportResult) { | |
| //Play the video from the path you specified below | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ExoPlayer player = ExoPlayer.Builder(this).build() | |
| player?.playWhenReady = true | |
| val mediaSource = downloadTracker?.getDownloadRequest(Uri.parse(VIDEO_URL))!!.let { | |
| DownloadHelper.createMediaSource( | |
| it, | |
| DemoUtil.getDataSourceFactory(this) | |
| ) | |
| } | |
| player?.setMediaSource(mediaSource) | |
| player?.prepare() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void toggleDownload( | |
| FragmentManager fragmentManager, | |
| MediaItem mediaItem, | |
| RenderersFactory renderersFactory | |
| ) { | |
| Download download = downloads.get(checkNotNull(mediaItem.localConfiguration).uri); | |
| if (download != null && download.state != Download.STATE_FAILED) { | |
| DownloadService.sendRemoveDownload( | |
| /* context= */ context, | |
| /* DownloadService= */ OfflineVideoDownloadService.class, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomContract : ActivityResultContract<String, String?>() { | |
| const val DATA = "data" | |
| const val INPUT_DATA = "input_data" | |
| override fun createIntent(context: Context, input: String?): Intent { | |
| val intent = Intent(context, DummyResultActivity::class.java) | |
| intent.putExtra(INPUT_DATA, input) | |
| return intent | |
| } |
NewerOlder