forked from imefGames/ProjetEi4_Android
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package roboyard; | ||
|
||
import android.app.Service; | ||
import android.content.Intent; | ||
import android.media.MediaPlayer; | ||
import android.os.IBinder; | ||
|
||
import roboyard.eclabs.MainActivity; | ||
import roboyard.eclabs.R; | ||
|
||
public class SoundService extends Service { | ||
MediaPlayer player; | ||
|
||
@Override | ||
public IBinder onBind(Intent intent) { | ||
return null; | ||
} | ||
|
||
public void onCreate() { | ||
int MAX_VOLUME = 100; | ||
float soundVolume = 10; | ||
player = MediaPlayer.create(this, R.raw.singing_bowls_in_a_forest); //select music file | ||
player.setLooping(true); //set looping | ||
final float volume = (float) (1 - (Math.log(MAX_VOLUME - soundVolume) / Math.log(MAX_VOLUME))); | ||
player.setVolume(volume, volume); | ||
} | ||
|
||
public int onStartCommand(Intent intent, int flags, int startId) { | ||
player.start(); | ||
return Service.START_NOT_STICKY; | ||
} | ||
|
||
public void onDestroy() { | ||
player.stop(); | ||
player.release(); | ||
stopSelf(); | ||
super.onDestroy(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.