gpt4 book ai didi

android - 将艺术品附加到 ExoPlayer 的 mp3 Uri

转载 作者:行者123 更新时间:2023-12-05 07:45:07 27 4
gpt4 key购买 nike

我正在使用或多或少的默认 ExoPlayer 2.1 SimpleExoPlayer 从 url Uri 或本地文件进行流式传输 URIUri 被加载到 MediaSource 中,

MediaSource mediaSource = new ExtractorMediaSource(url,
dataSourceFactory, extractorsFactory, null, null);

源有时是视频,mp4 而不是 mp3,因此在 Activity 中我它设置为 com。 google.android.exoplayer2.ui.SimpleExoPlayerView

 mVideoView = (SimpleExoPlayerView) findViewById(R.id.media_player);
mVideoView.setPlayer(player);
mVideoView.requestFocus();

我读过 article :

SimpleExoPlayerView has also been updated to look at ID3 metadata, and will automatically display embedded ID3 album art during audio playbacks. If not desired, this functionality can be disabled using SimpleExoPlayerView’s setUseArtwork method.

我已经看到它对 File 的回答,How to get and set (change) ID3 tag (metadata) of audio files? ,

但我希望为从 url String 派生的 Uri 设置 ID3 元数据。是否可以?否则,是否可以为 ExoPlayerView 编辑 ID3 图元文件设置艺术作品?或者可以更改 File 的 ID3 meta 而无需依赖项?

编辑

所以我找到了一个 Issue这表示这已解决,发行者链接到 exo_simple_player_view here 的覆盖

我在博文中找到了

When a SimpleExoPlayerView is instantiated it inflates its layout from the layout file exo_simple_player_view.xml. PlaybackControlView inflates its layout from exo_playback_control_view.xml. To customize these layouts, an application can define layout files with the same names in its own res/layout* directories. These layout files override the ones provided by the ExoPlayer library.

所以我必须覆盖 simpleview不知何故。

最佳答案

您可以使用此函数并将 mediaUri 和 thunbnailUri 传递给它

private fun PlayerView.loadArtWorkIfMp3(mediaUri: Uri, thumbnailUri: Uri) {
try {
val imageView = this.findViewById<ImageView>(R.id.exo_artwork)
if (mediaUri.lastPathSegment!!.contains("mp3")) {
this.useArtwork = true
imageView.scaleType = ImageView.ScaleType.CENTER_INSIDE
imageView.loadImage(thumbnailUri) {
this.defaultArtwork = it
}
}
} catch (e: Exception) {
Log.d("artwork", "exo_artwork not found")
}
}

并且您将使用 loadImage 函数

@BindingAdapter(value = ["imageUri", "successCallback"], requireAll = false)
fun ImageView.loadImage(imgUrl: Uri?, onLoadSuccess: (resource: Drawable) -> Unit = {}) {

val requestOption = RequestOptions()
.placeholder(R.drawable.ic_music)
.error(R.drawable.ic_music)

Glide.with(this.context)
.load(imgUrl)
.transition(DrawableTransitionOptions.withCrossFade())
.apply(requestOption)
.centerInside()
.diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
.listener(GlideImageRequestListener(object : GlideImageRequestListener.Callback {
override fun onFailure(message: String?) {
Log.d("loadImage", "onFailure:-> $message")
}

override fun onSuccess(dataSource: String, resource: Drawable) {
Log.d("loadImage", "onSuccess:-> load from $dataSource")
onLoadSuccess(resource)
}

}))
.into(this)
}

最后一个

class GlideImageRequestListener(private val callback: Callback? = null) : RequestListener<Drawable> {

interface Callback {
fun onFailure(message: String?)
fun onSuccess(dataSource: String, resource: Drawable)
}

override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
callback?.onFailure(e?.message)
return false
}

override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {

resource?.let {
target?.onResourceReady(
it,
DrawableCrossFadeTransition(1000, isFirstResource)
)
}
callback?.onSuccess(dataSource.toString(),resource!!)
return true
}


}

关于android - 将艺术品附加到 ExoPlayer 的 mp3 Uri,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42182249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com