kikuchi
kikuchi

Reputation: 251

Play separate video and audio simultaneously in android's videoview

I'm trying to play simultaneously a video and a different audio track from the video. I use a video view :

VideoView video = (VideoView) findViewById(R.id.VideoView);
video.setVideoPath(filename);
video.setOnCompletionListener(this);
video.start();
video.requestFocus();

Is it possible to handle this extra audio with MediaPlayer or I have to use SoundPool or AudioTrack ? If so, how can I be sur the audio and the video will be play in sync.

Thanks.

Upvotes: 2

Views: 1354

Answers (1)

Espen
Espen

Reputation: 11

You can start the video as normal, and then play the sound from a service running in the background. The service could contain a MediaPlayer for playing separate sound

About services: Services

And from your VideoView you can start the service by:

    playbackServiceIntent = new Intent(getActivity(), MusicPlayerService.class);
    getActivity().startService(playbackServiceIntent);

There might be issues with regards sound sync, but might be worth a try.

Upvotes: 1

Related Questions