How can I get sound working in an Android app running on a Raspberry Pi?

I am writing an Android app on Android Things platform on a Raspberry Pi 3. So far I have a simple app with one main move. I put the button in the breadboard and connected the mouse to the Pi so that I can press the button. I am trying to get a button click handler to play an MP3 audio file; here's a piece of code:

public class MainActivity extends AppCompatActivity {

    private MediaPlayer mediaPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mediaPlayer = MediaPlayer.create(this, R.raw.test_audio);
    }

    public void myButtonOnClick(View view) {
        mediaPlayer.start();
    }

    // ...
}

      

When I run this on android emulator it works fine. I hear a sound. But when I move this to my Raspberry Pi 3 running Android Things, it no longer plays a sound when I press the button. I've tried listening to both the 3.5mm audio jack and the HDMI port (i.e. it's connected to a TV that can play audio from the HDMI input). Why is the sound not working?

+3


source to share





All Articles