1

我似乎无法在我的设备(Nexus 7)上播放视频。我决定重新开始一个新项目来解决这个问题。

视频存储在 res/raw 中。
就是这个视频: http: //www.howtodance.org/media/Lesson_2__9_lindy_demo_2__shoulder_pop_with_scoop_around.mp4

我已经尝试了许多在 stackoverflow 上建议的方法。这是我尝试过的最新方法:

    <!-- 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
    }

}

添加文件对象后,对话框终于出现了,但随后我收到一条消息“无法播放此视频”和以下错误:

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”这样的短名称,但也会出现同样的错误

提前感谢大家的帮助。

4

1 回答 1

0

问题最终是我试图让他们选择他们想要使用哪个视频播放器来播放内部视频文件并且在本地存储上无法访问。我最终在子活动中使用了本地 VideoView。

于 2013-02-03T02:10:01.867 回答