diff --git a/src/com/androidhive/musicplayer/MusicPlayerActivity.java b/src/com/androidhive/musicplayer/MusicPlayerActivity.java index b699157..ec5b199 100644 --- a/src/com/androidhive/musicplayer/MusicPlayerActivity.java +++ b/src/com/androidhive/musicplayer/MusicPlayerActivity.java @@ -18,6 +18,7 @@ import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.View; +import android.view.WindowManager; import android.widget.ImageButton; import android.widget.SeekBar; import android.widget.TextView; @@ -40,6 +41,8 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene // Media Player private MediaPlayer mp; // Handler to update UI timer, progress bar etc,. + private WindowManager.LayoutParams layout; + private Handler mHandler = new Handler(); private SongsManager songManager; private Utilities utils; @@ -54,6 +57,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.pl_player); + + layout = getWindow().getAttributes(); + Log.d(LOG_TAG, "onCreate()"); // All player buttons btnPlay = (ImageButton) findViewById(R.id.btnPlay); @@ -265,6 +271,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene @Override public void onClick(View arg0) { + layout.screenBrightness = -1; + getWindow().setAttributes(layout); + Intent i = new Intent(getApplicationContext(), PlayListActivity.class); startActivityForResult(i, 100); } @@ -275,6 +284,7 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene @Override protected void onResume() { super.onResume(); + resumeSong(); } @@ -292,6 +302,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene } else { playng=true; } + + layout.screenBrightness = 0.1f; + getWindow().setAttributes(layout); } return playng; @@ -306,10 +319,10 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(resultCode == 100){ - currentSongIndex = data.getExtras().getInt("songIndex"); + currentSongIndex = data.getExtras().getInt("songIndex"); Log.d(LOG_TAG, "onActivityResult(), dalla playlist "+currentSongIndex); - // play selected song - playSong(currentSongIndex); + // play selected song + playSong(currentSongIndex); } } @@ -322,6 +335,10 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene // Play song try { Log.d(LOG_TAG, "playSong() "+songIndex); + + layout.screenBrightness = 0.1f; + getWindow().setAttributes(layout); + mp.reset(); mp.setDataSource(songsList.get(songIndex).get("songPath")); mp.prepare(); @@ -448,6 +465,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene if(mp != null) { if(mp.isPlaying()){ mp.pause(); + + layout.screenBrightness = -1; + getWindow().setAttributes(layout); } } } @@ -456,6 +476,8 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene public void onDestroy(){ Log.d(LOG_TAG, "onDestroy()"); super.onDestroy(); + layout.screenBrightness = -1; + getWindow().setAttributes(layout); if(mp != null) { mHandler.removeCallbacks(mUpdateTimeTask); mp.release();