我制作了以 3gp 格式播放电影的应用程序。一切都在智能手机上运行良好。当我在平板电脑上安装应用程序时,播放电影时出现奇怪的事情。整个布局是纵向模式,但电影旋转 90 度并以这种方式播放横向(与纵向模式相同的大小)。
我已经在清单文件android:screenOrientation="portrait"
中设置了VideoView
. 我根本不想以横向模式显示。
在禁用自动旋转屏幕的智能手机上 - 默认方向是纵向。在平板电脑上,默认方向是横向。平板电脑上的另一件事是当我使用 Youtube 应用程序并以纵向模式选择一些电影时,会自动旋转视频,调整大小并固定为横向模式。
我不确定我可以更改的是硬件设置或应用程序。
目前在平板电脑上,我的应用程序正在以纵向模式播放具有旋转视图的电影。
编辑:清单文件:
<activity android:name=".Video" android:screenOrientation="portrait" />
代码:
ByteArrayInputStream inputStream = new ByteArrayInputStream(cursor.getBlob(2)); //get from database
stream = inputStream;
if (stream == null)
throw new RuntimeException("stream is null");
try {
temp = File.createTempFile("movie", "3gp");
} catch (IOException e1) {
e1.printStackTrace();
}
temp.deleteOnExit();
tempPath = temp.getAbsolutePath();
try {
out = new FileOutputStream(temp);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
byte buf[] = new byte[128];
do {
try {
numread = stream.read(buf);
} catch (IOException e) {
e.printStackTrace();
}
if (numread <= 0)
break;
try {
out.write(buf, 0, numread);
} catch (IOException e) {
e.printStackTrace();
}
} while (true);
try {
stream.close();
} catch (IOException ex) {
Log.e("ERROR", "error: " + ex.getMessage(), ex);
}
final VideoView myVideoView = new VideoView(this);
myVideoView.setVideoPath(tempPath);
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
myVideoView.start();
}
});
myVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
mp.reset();
myVideoView.setVideoPath(tempPath);
}
});
tl.addView(myVideoView); //add videoview to table layout
布局.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tlomain">
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tlayout"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</TableLayout>
</RelativeLayout>
根据纵向模式,平板电脑屏幕上的所有元素都很好,只有视频旋转了 90 度。
您可以使用 Youtube 查看它的外观:http: //i.stack.imgur.com/qwP5S.jpg
影片旋转。在我的智能手机上,Youtube 应用程序中的同一部电影在水平视图中设置为正常。
我不知道如何在我的应用程序中更改它。是硬件设置吗?如果平板设备要打开 3gp、mp4 格式,它会旋转 90 度以准备横向模式?