我的源代码是应用程序来介绍当我们旋转他们的设备时可以旋转的视频。因为我必须剪辑一幅肖像一幅风景。但我不知道当用户选择我的应用程序时自动实现 onConfigurationChange。你能帮我解决问题吗?
package nahu.jl.intro;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
public class Nahu_videoIntroActivity extends Activity {
/** Called when the activity is first created. */
VideoView videoHolder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getWindow().setFormat(PixelFormat.TRANSLUCENT);
videoHolder = (VideoView) findViewById(R.id.myvideoview);
// set controller for video
String sdCard=Environment.getExternalStorageDirectory().getPath();
videoHolder.setMediaController(new MediaController(this));
Toast.makeText(Nahu_videoIntroActivity.this, sdCard, Toast.LENGTH_SHORT).show();
// get path to video from
// // start video
}
/* (non-Javadoc)
* @see android.app.Activity#onConfigurationChanged(android.content.res.Configuration)
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.ORIENTATION_PORTRAIT){
Uri videoUri = Uri.parse("android.resource://nahu.jl.intro/raw/intro2");
// set url to Video
videoHolder.setVideoURI(videoUri);
videoHolder.requestFocus();
// start video
videoHolder.start();
}
else{
Uri videoUri = Uri.parse("android.resource://nahu.jl.intro/raw/intro1");
// set url to Video
videoHolder.setVideoURI(videoUri);
videoHolder.requestFocus();
// start video
videoHolder.start();
}
}
//
public void onCompletion(MediaPlayer mp) {
finish();
}
}