This file contains 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 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 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 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 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 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 | |
} |
This file contains 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 mediaItem = MediaItem.fromUri(VIDEO_URL) | |
val mediaSource = | |
HlsMediaSource.Factory(cacheDataSourceFactory).createMediaSource(mediaItem) | |
player.setMediaSource(mediaSource) |
This file contains 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 cacheSink = CacheDataSink.Factory() | |
.setCache(downloadCache) | |
val upstreamFactory = DefaultDataSource.Factory(this, DefaultHttpDataSource.Factory()) | |
val downStreamFactory = FileDataSource.Factory() | |
val cacheDataSourceFactory = | |
CacheDataSource.Factory() | |
.setCache(downloadCache) | |
.setCacheWriteDataSinkFactory(cacheSink) | |
.setCacheReadDataSourceFactory(downStreamFactory) | |
.setUpstreamDataSourceFactory(upstreamFactory) |
This file contains 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 DOWNLOAD_CONTENT_DIRECTORY = "downloads" | |
val downloadContentDirectory = | |
File(getExternalFilesDir(null),DOWNLOAD_CONTENT_DIRECTORY) | |
var downloadCache = | |
SimpleCache(downloadContentDirectory, NoOpCacheEvictor(), StandaloneDatabaseProvider(this)) |
This file contains 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 defaultHttpDataSourceFactory = DefaultHttpDataSource.Factory() | |
val drmConfig = MediaItem.DrmConfiguration.Builder(C.WIDEVINE_UUID) | |
.setLicenseUri(LICENSE_URL) | |
val mediaItem = MediaItem.Builder() | |
.setUri(VIDEO_URL) | |
.setDrmConfiguration(drmConfig.build()) | |
val mediaSource = DashMediaSource.Factory(defaultHttpDataSourceFactory) | |
.createMediaSource(mediaItem.build()) | |
player.setMediaSource(mediaSource) |
NewerOlder