Comments (4)
If you are referring to comment like this one, I think the approach should still work as the underlying code hasn't changed in any significant ways since.
There is also ongoing work to allow proper audio mixing for playback of multiple tracks, but this may not be available soon.
Could you clarify in more detail what exactly isn't working and maybe we can point you in the right direction?
from media.
//initilize
private val exoPlayer by lazy {
ExoPlayer.Builder(this, renderersFactory).setTrackSelector(trackSelector).build()
}
//create media sources
val audioThreeFile = File(File(filesDir, "audio_test"), "audio_one_trimed.mp3")
val audioFourFile = File(File(filesDir, "audio_test"), "auudio_two_trimed.mp3")
val defaultDataSourceFactory = DefaultDataSource.Factory(applicationContext)
val sourceOne = ProgressiveMediaSource.Factory(defaultDataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.fromFile(audioThreeFile)))
val sourceTwo = ProgressiveMediaSource.Factory(defaultDataSourceFactory)
.createMediaSource(MediaItem.fromUri(Uri.fromFile(audioFourFile)))
val mergingMediaSource = MergingMediaSource(true, sourceOne, sourceTwo)
exoPlayer.setMediaSource(mergingMediaSource)
exoPlayer.prepare()
exoPlayer.playWhenReady = true
//create renderersFactory
private val renderersFactory = object : DefaultRenderersFactory(this) {
override fun buildAudioRenderers(
context: Context,
extensionRendererMode: Int,
mediaCodecSelector: MediaCodecSelector,
enableDecoderFallback: Boolean,
audioSink: AudioSink,
eventHandler: Handler,
eventListener: AudioRendererEventListener,
out: ArrayList<Renderer>
) {
super.buildAudioRenderers(
context,
extensionRendererMode,
mediaCodecSelector,
enableDecoderFallback,
audioSink,
eventHandler,
eventListener,
out
)
out.add(AudioRendererWithoutClock(context, mediaCodecSelector))
out.add(AudioRendererWithoutClock(context, mediaCodecSelector))
out.add(AudioRendererWithoutClock(context, mediaCodecSelector))
}
}
//create trackSelector
private val trackSelector = object : TrackSelector() {
override fun selectTracks(
rendererCapabilities: Array<out RendererCapabilities>,
trackGroups: TrackGroupArray,
periodId: MediaSource.MediaPeriodId,
timeline: Timeline
): TrackSelectorResult {
val audioRenderers: Queue<Int> = ArrayDeque()
val configs = arrayOfNulls<RendererConfiguration>(rendererCapabilities.size)
val selections = arrayOfNulls<ExoTrackSelection>(rendererCapabilities.size)
for (i in rendererCapabilities.indices) {
if (rendererCapabilities[i].trackType == C.TRACK_TYPE_AUDIO) {
audioRenderers.add(i)
configs[i] = RendererConfiguration.DEFAULT
}
}
for (i in 0 until trackGroups.length) {
if (MimeTypes.isAudio(trackGroups[i].getFormat(0).sampleMimeType)) {
val index = audioRenderers.poll()
if (index != null) {
selections[index] = FixedTrackSelection(trackGroups[i], 0)
}
}
}
return TrackSelectorResult(configs, selections, Any())
}
override fun onSelectionActivated(info: Any?) {
}
}
//create AudioRenderer
final class AudioRendererWithoutClock extends MediaCodecAudioRenderer {
public AudioRendererWithoutClock(Context context, MediaCodecSelector mediaCodecSelector) {
super(context, mediaCodecSelector);
}
@Override
public MediaClock getMediaClock() {
return null;
}
}
But getting this error-
![git_hub_error](https://private-user-images.githubusercontent.com/91248007/341059429-d10dce17-f4ac-456a-9fa8-9ca3c1692be1.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIyODM3MjEsIm5iZiI6MTcyMjI4MzQyMSwicGF0aCI6Ii85MTI0ODAwNy8zNDEwNTk0MjktZDEwZGNlMTctZjRhYy00NTZhLTlmYTgtOWNhM2MxNjkyYmUxLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MjklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzI5VDIwMDM0MVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTAyZTkwYTU0OWM3MTQzYjMyMTg2MDkzYmExNjE4YWY3ZTIxZTE1YzQ1NDg5MjUyNTNhNThiMjlhNTBjMTJhNmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.MXMO_uuCNW-vPLKjwO4Bm6psM7L2lD-mfhe4myT-JtQ)
from media.
Maybe the issue lies in the RenderersFactory where I am adding three new AudioRendererWithoutClock instances. However, I actually only need one additional AudioRendererWithoutClock to render the second audio.
from media.
Thanks for highlighting the problem! This is indeed related to the additional renderers. Having more renderers than needed is not usually an issue, but there is a bug in the TrackSelector
code I provided in the GitHub issue. The configs[i] = RendererConfiguration.DEFAULT
line needs to move further down to where we decide which renderer to use. I fixed my original post in google/ExoPlayer#6589 (comment) too to avoid further confusion. Note that this is still just an example though and it wouldn't handle other renderer types like video.
from media.
Related Issues (20)
- NetworkTypeObserver makes binding calls on mainthread by default HOT 2
- Getting the decoded from ExoPlayer in advance HOT 6
- Playing a song using MediaSessionService randomly turns on and off bluetooth for some reason on Android 11. HOT 9
- Render subtitles (Cue objects) via an Effect HOT 4
- Current application thread check for player.createMessage HOT 4
- Creating a perpetually loading MediaItem HOT 3
- HttpMediaDrmCallback setKeyRequestProperty PSSH name for header request HOT 1
- Media resumption results in DeadObjectException HOT 2
- Libflac decoder crash: flac_jni.cc (NewStringUTF)
- onVideoSizeChanged should be called before the frame has been written to surface
- How to overlay audio over video and preview in composition Player HOT 1
- DRM Video Playback: Black Screen with Audio Playing HOT 3
- HOWTO: Use DRM with CastPlayer HOT 1
- Android Auto ExoPlayer seeking of the audio track creates error while seeking to the end of the track HOT 1
- How can I play 360 stereoscopic vr video in ExoPlayer HOT 2
- hls+clearkey compatibility
- Unable to play an online stream HOT 1
- Preload Manager intermittent crash when devices is offline HOT 1
- External subtitle with 1.4.0 HOT 1
- CacheWriter cant write cache. ErrnoException open failed: ENOENT HOT 1
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.