我的源代码是引入视频的应用程序,当我们旋转它们时,它可以旋转。因为我必须剪一幅肖像一幅风景。但我不知道当用户选择我的应用程序时自动实现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();
}
}
答案 0 :(得分:0)
在清单文件
的活动代码中使用此功能 <activity android:name=".VideoActivity" android:label="" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:screenOrientation="sensor" android:configChanges="orientation"/>