【问题标题】:Why can't I see video in emulator?为什么模拟器看不到视频?
【发布时间】:2011-01-01 10:04:28
【问题描述】:

我见过几个类似的问题,但我想确定.. 我无法在我的模拟器上运行视频。是否一致?有人在模拟器上成功运行视频了吗?

以下是我使用的代码:

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”是 mp4 或 3gp(在这两种情况下都不起作用)

main.xml如下:

<?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>

并且清单是默认清单。 如果我的代码有问题,谁能告诉我? p.s.我正在使用 android 2.2 环境运行模拟器。

【问题讨论】:

  • 在这里发布您遇到的问题并格式化代码
  • 我收到“抱歉,无法播放此视频”错误。
  • 我认为模拟器存在问题,因为对我来说,当您在设备上运行应用程序而不是在模拟器上运行时会播放视频......

标签: android video emulation


【解决方案1】:

模拟器在播放某些视频时确实存在问题,因此我一直在实际设备上进行所有视频测试。当视频在模拟器上运行时,它通常非常慢(1fps,偏移声音)。我也建议不要将视频存储在 APK 中,但是,也就是说,我相信您需要在包名称后添加一个斜杠:

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

【讨论】:

  • 感谢您的回复。我已经想通了(斜线的事情)。现在我可以运行 3gp 文件了。 mp4 视频仍未播放。
猜你喜欢
  • 2019-05-23
  • 1970-01-01
  • 2014-12-09
  • 1970-01-01
  • 2015-07-08
  • 2020-11-12
  • 2017-10-26
  • 2017-04-01
  • 1970-01-01
相关资源
最近更新 更多