Why can't I see video in emulator?

2019-06-01 10:24发布

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条回答
对你真心纯属浪费
2楼-- · 2019-06-01 10:57

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);
查看更多
登录 后发表回答