John R
John R

Reputation: 2064

How to play sound using service in android

I want to play sound in my android app. And maybe I have to use service for this. But from this question I see on home button pressed and on screen lock onPause method called. But in case of home button pressed I want to stop sound in case of screen lock i dont want to stop sound. So how to do this and how to use onPause method in this case?

Please someone help me. Thanks...

Upvotes: 1

Views: 4657

Answers (1)

Ferzinha Fil
Ferzinha Fil

Reputation: 142

Use MediaPlayer from Android. See: Android Example

MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1);
mediaPlayer.start();

Upvotes: 1

Related Questions