I am new to android and I am now doing an exercise which the application has already stored a audio file(mp4) in /res/raw/ folder and this file can be referenced in android Service class as R.raw.audiofile
. In the Service class I have created three methods
onCreate();
onStartCommand();
onDestroy();
in onCreate()
I have created a MediaPlayer
and in onStartCommand()
I have started the MediaPlayer
mp.start() and
returned STRT_STICKY
to play it and in onDestroy()
I have done this:
mp.stop();
in the xml layout I have created a Button with this attribute:
android:onClick="onClickStart"
which calls a method in the MainActivity and this action now shoud playback the audio. however, I am now stuck here on how to link this to the music file so that this button should start the audio. can anyone please give me some idea?
so I have one Main activity class and one (My)Service class (extends to Servcie) and one xml file for layout to perform this action.