我有一个无法解决的问题。 我正在利用媒体宣传员的班子播放录像;然而,我总是在传播原来的比例。 这里提到了媒体参与者守则和xml守则。 我曾尝试过这么多事情,但仍然无法解决这个问题。 我需要保持原来的方面比率。 我已宣布,这项活动将在我安妮斯·马尼费斯的档案中充分放映。 在媒体参与者守则之后,我也在此附上了xml代码。 请通知我。
private class ErrorListener implements OnErrorListener {
// FIXME: @Override
public boolean onError(MediaPlayer mp, int what, int extra) {
String message = "Unknown error";
switch (what) {
case MediaPlayer.MEDIA_ERROR_UNKNOWN:
message = "Unable to play media";
showError(message);
break;
case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
message = "Server failed";
showError(message);
break;
case MediaPlayer.MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK:
message = "Invalid media";
showError(message);
break;
}
return false;
}
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.videoview);
Intent intent = getIntent();
uri = intent.getData();
new loadMovie().execute();
mPreview = (SurfaceView) findViewById(R.id.videoview);
mPreview.bringToFront();
holder = mPreview.getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
mediaPlayer = new MediaPlayer();
}// onCreate Method Ends
private void playVideo() {
doCleanUp();
try {
mediaPlayer.setDataSource(this, uri);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setDisplay(holder);
try {
mediaPlayer.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mediaPlayer.setOnErrorListener(new ErrorListener());
mediaPlayer.setOnBufferingUpdateListener(this);
mediaPlayer.setOnCompletionListener(this);
mediaPlayer.setOnPreparedListener(this);
mediaPlayer.setOnVideoSizeChangedListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaController = new MediaController(this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
mediaController.show();
return false;
}
// --MediaPlayerControl
// methods----------------------------------------------------
public void start() {
mediaPlayer.start();
}
public void pause() {
mediaPlayer.pause();
}
public int getDuration() {
return mediaPlayer.getDuration();
}
public int getCurrentPosition() {
return mediaPlayer.getCurrentPosition();
}
public void seekTo(int i) {
mediaPlayer.seekTo(i);
}
public boolean isPlaying() {
return mediaPlayer.isPlaying();
}
public int getBufferPercentage() {
return 0;
}
public boolean canPause() {
return true;
}
public boolean canSeekBackward() {
return true;
}
public boolean canSeekForward() {
return true;
}
// End of MediaPlayer
// Controls--------------------------------------------------------
// ------------------------
public void onPrepared(MediaPlayer mediaPlayer) {
mediaController.setMediaPlayer(this);
mediaController.setAnchorView(findViewById(R.id.videoview));
mIsVideoReadyToBePlayed = true;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
handler.post(new Runnable() {
public void run() {
mediaController.setEnabled(true);
mediaController.show();
}
});
}
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void surfaceCreated(SurfaceHolder holder) {
// TODO Auto-generated method stub
playVideo();
}
public void surfaceDestroyed(SurfaceHolder arg0) {
}
private void startVideoPlayback() {
holder.setFixedSize(mVideoWidth, mVideoHeight);
mediaPlayer.start();
}
public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
if (width == 0 || height == 0) {
return;
}
mIsVideoSizeKnown = true;
mVideoWidth = width;
mVideoHeight = height;
if (mIsVideoReadyToBePlayed && mIsVideoSizeKnown) {
startVideoPlayback();
}
}
public void onCompletion(MediaPlayer arg0) {
}
public void onBufferingUpdate(MediaPlayer mp, int percent) {
}
private void releaseMediaPlayer() {
mediaPlayer.release();
mediaPlayer = null;
}
private void doCleanUp() {
mVideoWidth = 0;
mVideoHeight = 0;
mIsVideoReadyToBePlayed = false;
mIsVideoSizeKnown = false;
}
这里是《刑法》:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<SurfaceView android:id="@+id/videoview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
请允许我告诉我,我如何能够保持视频的那部分比例?