Comments (2)
Specifically one difficulty I encountered is that HLS uses the file extension.
https://exoplayer.dev/hls.html
If your URI doesn’t end with .m3u8, you can pass MimeTypes.APPLICATION_M3U8 to setMimeType of MediaItem.Builder to explicitly indicate the type of the content.
It seems quite awkward to configure this, using a MediaItemFiller that knows to set mimetype based on the app specific urls.
from media.
I've got this working via a couple of mechanisms.
fun streamInterceptor(moshi: Moshi): Interceptor {
val adapter = moshi.adapter(Stream::class.java)
return Interceptor { chain ->
val request = chain.request()
var response = chain.proceed(request)
val body = response.body
if (isStreamJson(response) && body != null) {
val gzipped = "gzip".equals(response.header("Content-Encoding"), ignoreCase = true)
val source = if (gzipped) GzipSource(body.source()).buffer() else body.source()
val stream = adapter.fromJson(source)
source.close()
response = response.newBuilder()
.code(307)
.header("Location", stream!!.url)
.body(ByteArray(0).toResponseBody())
.build()
}
response
}
}
private fun isStreamJson(response: Response) =
response.body?.contentType()?.subtype == "json"
&& response.code == 200
&& response.request.url.host == "api.xxx.com"
&& response.request.url.pathSegments.firstOrNull() == "media"
and MediaSourceFactory
override fun createMediaSource(mediaItem: MediaItem): MediaSource {
val uri = mediaItem.localConfiguration?.uri
return when (uri?.lastPathSegment) {
"hls" -> HlsMediaSource.Factory(dataSourceFactory).createMediaSource(uri)
"progressive" -> ProgressiveMediaSource.Factory(dataSourceFactory, extractorsFactory)
.createMediaSource(uri)
else -> delegate.createMediaSource(mediaItem)
}
}
from media.
Related Issues (20)
- OOM probably due to bad file
- Playback speed doesn't work on some devices with Audio Offload Enabled
- How to pass the tag in MediaItem to the customData of DataSpec?
- Android Auto Grid Layout with Media3 HOT 4
- Exoplayer.release did not free memory? Is it a Known issues??2.11.8 and 2.19.1
- Exoplayer does not resume once the Ad creative load is blocked via Charles
- "Session ID must be unique. ID=" when building a session HOT 4
- Rename setShowPlayButtonIfPlaybackIsSuppressed in MediaSession.Builder
- i'm facing an issue regarding the media3 exo player controlls position in a horizoantal tab . HOT 1
- Controlls position in a horizontal orientation with RESIZE_MODE_FILL HOT 2
- Add charles/fiddler... proxy block when playing hls media
- Player does not upscale LL Stream once it get to lowest resolution HOT 6
- Video is cut on the edge when using Compose and uses RESIZE_MODE_ZOOM - Only Android 14 HOT 1
- [CMCD] Too many buffer starvation reports HOT 5
- Equalizer support
- ERROR_CODE_IO_UNSPECIFIED error on HLS stream HOT 10
- TTML subtitles - Opacity not compliant with TTML specification HOT 6
- [Transformer] Overlay rotation around the X and Y axles HOT 2
- How to set defaultPositionUs of a Window in the Timeline? HOT 2
- Non-Exoplayer TimeBar with Exoplayer Function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media.