Why can't I see video in emulator?

耗尽温柔 提交于 2019-12-08 03:47:39

问题


I have seen few questions similar to this one, but I wanted to make sure.. I fail running video on my emulator. Is it consistent? Does anyone succeeded running a video on the emulator?

The following is the code I use:

import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.VideoView;

public class TTTTest extends Activity {
    /** Called when the activity is first created. */
 private MediaController mc;
 VideoView vd;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        vd = (VideoView) findViewById(R.id.VideoView);

        Uri uri = Uri.parse("android.resource://" + getPackageName() + R.raw.samplevideo);

        mc = new MediaController(this);
        vd.setMediaController(mc);

        vd.setVideoURI(uri);
        vd.start();
    }
}

"samplevideo" is either mp4 or 3gp (in both cases its not working)

main.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
 <VideoView android:layout_height="fill_parent"
  android:layout_width="fill_parent"
  android:id="@+id/VideoView"></VideoView>
</LinearLayout>

and the manifest is the default one. Can anyone please tell me if I have a problem with my code? p.s. I am running the emulator using android 2.2 environment.


回答1:


The emulator does have issues playing some videos, so I have always done all video testing on actual devices. When video does work on the emulator, it is typically extremely slow (1fps, offset sound) at best. I also recommend not storing the videos in the APK, but, that said, I believe you need another slash after your package name:

Uri uri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.samplevideo);


来源:https://stackoverflow.com/questions/4573728/why-cant-i-see-video-in-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!