gpt4 book ai didi

android - 如何在 SurfaceView 中旋转视频 *.mp4?

转载 作者:太空宇宙 更新时间:2023-11-03 11:25:30 27 4
gpt4 key购买 nike

friend 。你能帮帮我吗?

我需要在单击按钮或其他时旋转视频(视频必须始终播放)。我在 SurfaceView 的 MediaPlayer 中显示视频并尝试这个:

@Override
public void surfaceCreated(SurfaceHolder holder) {
surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
surfaceHolder.lockCanvas().rotate(90);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);

try {
mediaPlayer.setDataSource(stringPath);
mediaPlayer.prepare();

} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}

mediaPlayer.start();
}
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}

但是视频不想播放。 (我不知道它是否旋转)帮帮我……任何人……非常感谢。

最佳答案

也许你可以试试这个:

 surfaceView = (SurfaceView)findViewById(R.id.surfaceview);     
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int h = displaymetrics.heightPixels;
int w = displaymetrics.widthPixels;

surfaceHolder = surfaceView.getHolder();

if (w > h) {
surfaceHolder.setFixedSize(w,h);
} else {
surfaceHolder.setFixedSize(h,w);
}

surfaceHolder.addCallback(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);

此外,也许您希望将上面的代码放在您的 onCreate() 上,而不是 surfaceCreated() 上。然后放置一些从某个按钮调用的 play() 方法:

protected void play() {
// TODO Auto-generated method stub

if(mediaPlayer.isPlaying()){
mediaPlayer.reset();
}
//Define here your filename:
String stringPath = Environment.getExternalStorageDirectory().getPath() + "/BigBuckBunny_320x180.mp4";

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setDisplay(surfaceHolder);

try {
mediaPlayer.setDataSource(stringPath);
mediaPlayer.prepare();

} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

mediaPlayer.start();
}

关于android - 如何在 SurfaceView 中旋转视频 *.mp4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14858214/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com