If the long running service is not at all started, then the error message is written into the log. Here an activity is used to trigger the service and also to stop the running services. This method will be invoked when the startService method is called from other application component. Next the onStartCommand() command is used to start the media player. ObjPlayer = MediaPlayer.create(this,R.raw.sleepaway) MediaPlayer.create() method is used to promote the state of the MediaPlayer instance from idle to prepared state. So this method deals with the preparatory functionality. The onCreate() method is called before any operations started with the media player instance. The corresponding callback functions are declared inside the class. Create a subclass for Service classĪ new java class named PlayAudio is created which extends Service class. URL url getClass ().getResource ('/foo/bar/sound.wav') AudioClip clip Applet.newAudioClip (url) ay () Here, the sound.wav file is bundled in the jar file in the foo/bar package that you create. Create an Activity to perform service related functionality.ĭownload Source Code of Android App to Play Audio 1. To avoid creating an Applet instance you can use the static newAudioClip method, and then call play () on the AudioClip created.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |