我尝试将视频放在Galaxy Tab 2上,然而,应用程序启动但我没有图像,我只有声音。所以我尝试在手机(Galaxy S2)上运行该应用程序,它的工作原理(声音+视频)(我的视频是尺寸为1280x800的mp4)。
代码:
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//VideoView view = new VideoView(this);
VideoView view = (VideoView)findViewById(R.id.view);
//view.setMediaController(new MediaController(this));
//setContentView(view);
view.setVideoURI(Uri.parse("android.resource://"+this.getPackageName()+"/"+R.raw.video4));
view.requestFocus();
view.start();
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<VideoView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:id="@+id/view"
android:layout_height="fill_parent" android:layout_alignParentRight="true"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:layout_alignParentBottom="true" android:layout_gravity="center">
</VideoView>
logcat的:
02-13 20:55:21.707: D/OpenGLRenderer(31903): Flushing caches (mode 1)
02-13 20:55:22.105: D/OpenGLRenderer(31903): Flushing caches (mode 0)
02-13 20:56:23.699: D/libEGL(31991): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
02-13 20:56:23.707: D/libEGL(31991): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
02-13 20:56:23.707: D/libEGL(31991): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
02-13 20:56:23.902: D/OpenGLRenderer(31991): Enabling debug mode 0
02-13 20:56:23.933: I/MediaPlayer(31991): path is null
02-13 20:56:24.050: W/MediaPlayer(31991): info/warning (901, 0)
02-13 20:56:24.199: I/MediaPlayer(31991): Info (901,0)
02-13 20:56:24.199: E/MediaPlayer(31991): mOnInfoListener is null. Failed to send MEDIA_INFO message.
02-13 20:56:24.207: D/MediaPlayer(31991): getMetadata
在这里,我尝试了它是相同的。
我改变了视频的格式(我把flv),它可以工作,但我又在logcat中遇到了问题:
02-15 21:53:06.189: D/libEGL(15791): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
02-15 21:53:06.189: D/libEGL(15791): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
02-15 21:53:06.196: D/libEGL(15791): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
02-15 21:53:06.321: D/OpenGLRenderer(15791): Enabling debug mode 0
02-15 21:53:06.345: I/MediaPlayer(15791): path is null
02-15 21:53:06.689: D/MediaPlayer(15791): getMetadata
02-15 21:53:12.978: W/IInputConnectionWrapper(15791): showStatusIcon on inactive InputConnection
答案 0 :(得分:0)
&#34;路径为空&#34;这可能是你的问题,确保uri是正确的。 android.resource也看起来不合适......仔细检查一下。
您也可以在致电开始之前等待准备完成:
试试这个URI:
file:///android_asset/(filename.here)