简体   繁体   中英

Playing the same music file in the same time on speaker and earpiece, Android

Is it possible to do it on android? Ofc I'm talking about phones that use only one speaker for media playback. My phone is Nexus5X. I dont want to root it or mess with system files cause of warranty. So can an app without root be made to do smth like that?
ps I tried SoundAbout didnt work.

I think you want to play a music file in phone speaker as well as Head Phone. If Yes means, It's Possible.

// Read the music file from the asset folder
            afd = this.getAssets().openFd("background_music.mp3");
// Creation of new media player;
            player = new MediaPlayer();
// Set the player music source.
            player.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
               player.setAudioStreamType(AudioManager.STREAM_ALARM);
// Set the looping and play the music.
            player.setLooping(true);
            player.prepare();
            player.start();

Here player.setAudioStreamType(AudioManager.STREAM_ALARM); will act as alarm service, means the audio in the asset folder will play in both headphones and speaker.

Hope it will Help you....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM