Force portrait mode for audio

This commit is contained in:
daniel oeh 2012-06-27 18:40:46 +02:00
parent 0eded316b3
commit 821dad45d2
1 changed files with 13 additions and 16 deletions

View File

@ -7,6 +7,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.media.MediaPlayer; import android.media.MediaPlayer;
@ -105,19 +106,16 @@ public class MediaplayerActivity extends SherlockActivity implements
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
Log.d(TAG, "Configuration changed"); Log.d(TAG, "Configuration changed");
orientation = newConfig.orientation; orientation = newConfig.orientation;
if (positionObserver != null) {
positionObserver.cancel(true); positionObserver.cancel(true);
}
if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
setContentView(R.layout.mediaplayer_activity); setContentView(R.layout.mediaplayer_activity);
} else { } else {
setContentView(R.layout.mediaplayer_activity); setContentView(R.layout.mediaplayer_activity);
} }
setupGUI(); setupGUI();
if (playbackService != null && playbackService.isPlayingVideo()) {
playbackService.resetVideoSurface();
if (!videoview.isShown()) {
viewswitcher.showNext();
}
}
} }
@Override @Override
@ -219,14 +217,7 @@ public class MediaplayerActivity extends SherlockActivity implements
break; break;
case AWAITING_VIDEO_SURFACE: case AWAITING_VIDEO_SURFACE:
Log.d(TAG, "Preparing video playback"); Log.d(TAG, "Preparing video playback");
SurfaceHolder holder = videoview.getHolder(); this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
playbackService.setVideoSurface(holder);
holder.addCallback(this);
if (orientation == Configuration.ORIENTATION_PORTRAIT) {
if (!videoview.isShown()) {
viewswitcher.showNext();
}
}
} }
} }
@ -294,7 +285,6 @@ public class MediaplayerActivity extends SherlockActivity implements
private void setupGUI() { private void setupGUI() {
viewswitcher = (ViewSwitcher) findViewById(R.id.viewswitcher); viewswitcher = (ViewSwitcher) findViewById(R.id.viewswitcher);
sbPosition = (SeekBar) findViewById(R.id.sbPosition); sbPosition = (SeekBar) findViewById(R.id.sbPosition);
videoview = (VideoView) findViewById(R.id.videoview);
txtvPosition = (TextView) findViewById(R.id.txtvPosition); txtvPosition = (TextView) findViewById(R.id.txtvPosition);
txtvLength = (TextView) findViewById(R.id.txtvLength); txtvLength = (TextView) findViewById(R.id.txtvLength);
@ -358,6 +348,8 @@ public class MediaplayerActivity extends SherlockActivity implements
}); });
} else { } else {
setTheme(R.style.Theme_Sherlock_Light_NoActionBar); setTheme(R.style.Theme_Sherlock_Light_NoActionBar);
videoview = (VideoView) findViewById(R.id.videoview);
videoview.getHolder().addCallback(this);
videoview.setOnClickListener(playbuttonListener); videoview.setOnClickListener(playbuttonListener);
} }
} }
@ -386,6 +378,11 @@ public class MediaplayerActivity extends SherlockActivity implements
media = playbackService.getMedia(); media = playbackService.getMedia();
registerReceiver(statusUpdate, new IntentFilter( registerReceiver(statusUpdate, new IntentFilter(
PlaybackService.ACTION_PLAYER_STATUS_CHANGED)); PlaybackService.ACTION_PLAYER_STATUS_CHANGED));
if (playbackService.isPlayingVideo()) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
handleStatus(); handleStatus();
Log.d(TAG, "Connection to Service established"); Log.d(TAG, "Connection to Service established");
} }