3

I am stuck to playing parallel diffrent Media streams in Exoplayer

Scenario:

  • I have one Audio MediaSource. and one Video MediaSource.
  • I want to play that both mediasource Parallelly in ExoPlayer

After lots of R&D i found

I am trying but failed to achive that. code of Example here

if (player == null) {
    player = ExoPlayerFactory.newSimpleInstance(ChangeAudioActivity.this, new DefaultRenderersFactory(this),
                new DefaultTrackSelector(), new DefaultLoadControl());
    playerView.setPlayer(player);
    player.setPlayWhenReady(playWhenReady);
    player.seekTo(currentWindow, playbackPosition);
}

MediaSource audiosource = new ProgressiveMediaSource.Factory(new FileDataSourceFactory()).createMediaSource(Uri.parse(videoModel.getAudio()));
MediaSource videoSource = new ProgressiveMediaSource.Factory(new FileDataSourceFactory()).createMediaSource(Uri.parse(videoModel.getVideo()));
player.prepare(new MergingMediaSource(videoSource , audiosource ), true, false);

I refer Exoplayer Docs also.

Is that Possible with Exoplayer? Thank you in Advance for Your Suggestions.

Nikunj Paradva
  • 15,332
  • 5
  • 54
  • 65

2 Answers2

0

This is an issue of Exoplayer But My Point of View its not an Issue because ExoPlayer was think with sense means....

  • If Already Your Video Has Audio so Why Second Audio you want to play ? so your input audio not add or play in exoplayer.
  • But you input Video Without Audio And also input Second Audio In Function So it's Work definitely.

I understand! you want to mix dual audio play with your video in exoPlayer but It not possible without any Editing

Sanjay Hadiya
  • 864
  • 9
  • 21
0

You can use two instances of Exoplayer, one for the video, one for the audio.

ZP007
  • 582
  • 7
  • 12
  • two instances is bad practice! – Nikunj Paradva Jan 15 '23 at 04:38
  • Why would it be bad practice? Imagine you need to implement a piano app. I'd create and cache for each key an ExoPlayer instance in memory, with the corresponding audio sample mp3 asset for each note. How would you implement this? – ZP007 Jan 15 '23 at 22:23