Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 5 files changed
  • 0 comments
  • 1 contributor
Feb 19, 2012
Jan Zalsky music player instead fo service 966133f
Jan Zalsky cleanup 789d65f
Jan Zalsky Merge branch 'devel' into turbo
Conflicts:
	src/cz/gug/hackathon/mantattan/MainActivity.java
	src/cz/gug/hackathon/mantattan/MusicService.java
20231d2
Jan Zalsky sound 8019809
2  AndroidManifest.xml
@@ -33,7 +33,7 @@
33 33
34 34 </activity>
35 35
36   - <service android:name=".MusicService"></service>
  36 +
37 37 </application>
38 38
39 39 </manifest>
0  assets/theme.ogg → res/raw/theme.ogg
File renamed without changes
53 src/cz/gug/hackathon/mantattan/MainActivity.java
@@ -2,7 +2,7 @@
2 2
3 3 import android.app.Activity;
4 4 import android.content.Intent;
5   -import android.media.AudioManager;
  5 +import android.media.MediaPlayer;
6 6 import android.os.Bundle;
7 7 import android.view.View;
8 8 import android.view.Window;
@@ -13,13 +13,18 @@
13 13
14 14 //private static final String TAG = MainActivity.class.getSimpleName();
15 15 //private DataTable dataTable;
16   -
  16 + private MediaPlayer mp ;
  17 +
17 18 @Override
18 19 public void onCreate(Bundle savedInstanceState) {
19 20 super.onCreate(savedInstanceState);
20 21 this.requestWindowFeature(Window.FEATURE_NO_TITLE);
21 22 setContentView(R.layout.main);
22   - this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
  23 +
  24 + mp = MediaPlayer.create(getApplicationContext(), R.raw.theme);
  25 + mp.start();
  26 +
  27 +
23 28 // dataTable = new DataTable(3, 2);
24 29 // Log.d(TAG, "====================================================");
25 30 // dataTable.shuffle(0);
@@ -47,4 +52,46 @@ public void onClick(View v) {
47 52
48 53
49 54 }
  55 +
  56 + @Override
  57 + protected void onResume() {
  58 + mp = MediaPlayer.create(getApplicationContext(), R.raw.theme);
  59 + if (!mp.isPlaying()){
  60 + mp.start();
  61 + }
  62 +
  63 + super.onResume();
  64 + }
  65 +
  66 + @Override
  67 + protected void onStart() {
  68 +
  69 + if (!mp.isPlaying()){
  70 + mp.start();
  71 + }
  72 +
  73 + super.onStart();
  74 + }
  75 +
  76 + @Override
  77 + protected void onPause() {
  78 +
  79 + if (mp.isPlaying()){
  80 + mp.stop();
  81 + }
  82 +
  83 + super.onPause();
  84 + }
  85 +
  86 + @Override
  87 + protected void onStop() {
  88 +
  89 + if (mp.isPlaying()){
  90 + mp.stop();
  91 + }
  92 +
  93 + super.onStop();
  94 + }
  95 +
  96 +
50 97 }
97 src/cz/gug/hackathon/mantattan/MusicService.java
... ... @@ -1,97 +0,0 @@
1   -package cz.gug.hackathon.mantattan;
2   -
3   -import java.io.IOException;
4   -
5   -import android.app.Service;
6   -import android.content.Intent;
7   -import android.content.res.AssetFileDescriptor;
8   -import android.content.res.AssetManager;
9   -import android.database.sqlite.SQLiteDatabase;
10   -import android.media.MediaPlayer;
11   -import android.media.MediaPlayer.OnPreparedListener;
12   -import android.os.IBinder;
13   -import android.util.Log;
14   -
15   -public class MusicService extends Service implements OnPreparedListener {
16   -
17   - static final String TAG = "MusicService";
18   -
19   - private WeedCrusherApp weedCrusherApp;
20   - AssetManager assetManager;
21   - MediaPlayer mediaPlayer;
22   - private boolean playerOK = false;
23   - private boolean runFlag = false;
24   - SQLiteDatabase db;
25   -
26   - @Override
27   - public void onCreate() {
28   - super.onCreate();
29   -
30   - weedCrusherApp = (WeedCrusherApp) getApplication();
31   - assetManager = getApplicationContext().getAssets();
32   -
33   - mediaPlayer = new MediaPlayer();
34   - AssetFileDescriptor descriptor;
35   - try {
36   - descriptor = assetManager.openFd("theme.ogg");
37   - mediaPlayer.setDataSource(descriptor.getFileDescriptor(),
38   - descriptor.getStartOffset(), descriptor.getLength());
39   - mediaPlayer.setOnPreparedListener(this);
40   - mediaPlayer.prepareAsync();
41   - mediaPlayer.setLooping(true);
42   -
43   - } catch (IOException e) {
44   - Log.d(TAG, "Unable to open audio file.");
45   - e.printStackTrace();
46   - } catch (IllegalStateException e) {
47   - Log.d(TAG, "Unable to start audio playback.");
48   - e.printStackTrace();
49   - }
50   -
51   - Log.d(TAG, "onCreated");
52   - }
53   -
54   - @Override
55   - public int onStartCommand(Intent intent, int flags, int startId) {
56   - super.onStartCommand(intent, flags, startId);
57   -
58   - this.runFlag = true;
59   -
60   - if (playerOK) {
61   - if (!(mediaPlayer.isPlaying())) {
62   - mediaPlayer.start();
63   - }
64   - this.weedCrusherApp.setMusicServiceRunning(runFlag);
65   - }
66   -
67   - Log.d(TAG, "onStarted");
68   - return START_STICKY;
69   - }
70   -
71   - @Override
72   - public void onDestroy() {
73   - super.onDestroy();
74   -
75   - this.runFlag = false;
76   - if (playerOK) {
77   - if (mediaPlayer.isPlaying()) {
78   - mediaPlayer.stop();
79   - mediaPlayer.release();
80   - }
81   - this.weedCrusherApp.setMusicServiceRunning(runFlag);
82   - }
83   -
84   - Log.d(TAG, "onDestroyed");
85   - }
86   -
87   - @Override
88   - public IBinder onBind(Intent arg0) {
89   - // TODO Auto-generated method stub
90   - return null;
91   - }
92   -
93   - public void onPrepared(MediaPlayer mp) {
94   - playerOK = true;
95   - }
96   -
97   -}
4 src/cz/gug/hackathon/mantattan/WeedCrusherApp.java
@@ -32,14 +32,14 @@ public void onCreate() { //
32 32 // this.prefs = PreferenceManager.getDefaultSharedPreferences(this);
33 33 // this.prefs.registerOnSharedPreferenceChangeListener(this);
34 34 dataTable = new DataTable(numRows, numCols);
35   - startService(new Intent(this, MusicService.class));
  35 +
36 36 Log.i(TAG, "onCreated");
37 37 }
38 38
39 39 @Override
40 40 public void onTerminate() { //
41 41 super.onTerminate();
42   - stopService(new Intent(this, MusicService.class));
  42 +
43 43 Log.i(TAG, "onTerminated");
44 44 }
45 45

No commit comments for this range

Something went wrong with that request. Please try again.