FAQ
- What do I do if I want to play music?
You can play some music in the background of your app using the
MediaPlayer
class. Here is some sample code to show how simple this can be:// Create a MediaPlayer object MediaPlayer mp = new MediaPlayer(); // Choose where to load the music from mp.setDataSource(musicFileToLoad); // Call the prepare method mp.prepare(); // Play some music mp.start();
Take a look at the official documentation for full details at http://developer.android.com/reference/android/media/MediaPlayer.html.
- How about if I want to make an actual music playing app where the user can select music from their library to play.
This is also made easy for us by Android. On the Android Studio palette, you can drag a MediaController widget, which not only allows your user to control music playback but video as well. Find out how to use this widget on the Android developer site, http://developer.android.com/reference/android/widget/MediaController.html.