-
Software Solution:
- Stealth Audio Player: This app allows you to play music through your phone’s earpiece speaker. Install it from the Google Play Store, grant it permission to access your phone’s storage, and it will scan your local music library. You can then enjoy a low-key listening experience through the earpiece speaker1.
-
Programmatic Solution (for developers):
- If you’re a developer and want to control this programmatically, you can use the AndroidÂ
AudioManager
class. Below is an example snippet in Java that demonstrates switching between the internal speaker and earpiece during playback using aÂMediaPlayer
:Javaimport android.media.MediaPlayer; import android.media.AudioManager; public class MyMediaPlayer { private MediaPlayer mMediaPlayer; private AudioManager mAudioManager; private boolean isPlayingOnSpeaker = false; // ... Other code ... // Inside your button click listener: mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Get the application context Context context = getActivity().getBaseContext(); // Initialize AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mAudioManager.setMode(AudioManager.STREAM_MUSIC); // Toggle between internal speaker and earpiece if (isPlayingOnSpeaker) { mAudioManager.setSpeakerphoneOn(false); isPlayingOnSpeaker = false; } else { mAudioManager.setSpeakerphoneOn(true); isPlayingOnSpeaker = true; } } }); }
R.raw.song
with your actual music resource2.
- If you’re a developer and want to control this programmatically, you can use the AndroidÂ
Remember that the second solution requires some programming knowledge, but it gives you more control over the behavior. Choose the one that best suits your needs!
android.gadgethacks.com
stackoverflow.com