视频android编程的困难(没有图像)



我试图在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

"Path为null"这可能是您的问题,请确保uri是正确的。还有android.resource看起来或听起来都不对。。。仔细检查一下。

更新

此外,在调用start:之前,您可能需要等待准备完成

http://developer.android.com/reference/android/widget/VideoView.html#setOnPreparedListener(android.media.MediaPlayer.OnPreparedListener)

更新

试试这个URI:

file:///android_asset/(filename.here)

相关内容

  • 没有找到相关文章

最新更新