我似乎无法在我的设备上播放视频(Nexus 7)。我决定为这个问题重新开始一个新的项目。
视频存储在res/raw中。
这是一个视频:around.mp4
我已经尝试了这里建议的许多方法在堆栈溢出。以下是我尝试过的最新成果:
    <!-- 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"
            >
        <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Button"
                android:id="@+id/button"
                android:layout_gravity="center"
                android:onClick="onButtonClick"
                />
    </LinearLayout>//MyActivity.java
package com.example.VideoTests;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import java.io.File;
public class MyActivity extends Activity {
    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    public void onButtonClick(View v){
        Log.d("working", "PlayVideo();");
        //  both of these urls don't seem to work
        //String uriString = "android.resource://com.example.VideoTests/raw/lesson_2__9_lindy_demo_2__shoulder_pop_with_scoop_around.mp4";
        String uriString = "android.resource://" + getPackageName() + "/" + R.raw.lesson_2__9_lindy_demo_2__shoulder_pop_with_scoop_around;
        //Uri video = Uri.parse(uriString);
        File file = new File(uriString); // video player selection dialog doesn't seem to load at all unless I send it through a file first.
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(file), "video/mp4");
        startActivity(intent); // this is where it seems to crash
    }
}在添加File对象之后,最终会出现一个对话框,但随后我会收到一条消息,上面写着“无法播放此视频”,下面的错误如下:
ERROR/(128): Failed to open file '/android.resource:/com.example.VideoTests/2130968576'. (No such file or directory)如果我使用另一个uriString,它仍然会给出以下错误:
ERROR/(128): Failed to open file '/android.resource:/com.example.VideoTests/raw/lesson_2__9_lindy_demo_2__shoulder_pop_with_scoop_around.mp4'. (No such file or directory)我还尝试将视频文件名更改为类似于'asdf.mp4‘的简短内容,但同样的错误也会发生。
谢谢大家的帮助。
发布于 2013-02-03 02:10:01
问题是,我试图让他们选择他们想要使用哪个视频播放器来播放一个在本地存储中无法访问的内部视频文件。最后,我在子活动中使用了一个本地VideoView。
https://stackoverflow.com/questions/14574132
复制相似问题