-
Software Solution:
- Stealth Audio Player: This app allows you to play music through your phone鈥檚 earpiece speaker. Install it from the Google Play Store, grant it permission to access your phone鈥檚 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鈥檙e 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鈥檙e 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