首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android4.2SDK- Nexus 7- res/raw中的mp4 -没有这样的文件-不能播放视频

Android4.2SDK- Nexus 7- res/raw中的mp4 -没有这样的文件-不能播放视频
EN

Stack Overflow用户
提问于 2013-01-29 01:19:22
回答 1查看 814关注 0票数 1

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

视频存储在res/raw中。

这是一个视频:around.mp4

我已经尝试了这里建议的许多方法在堆栈溢出。以下是我尝试过的最新成果:

代码语言:javascript
运行
复制
    <!-- 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>

代码语言:javascript
运行
复制
//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对象之后,最终会出现一个对话框,但随后我会收到一条消息,上面写着“无法播放此视频”,下面的错误如下:

代码语言:javascript
运行
复制
ERROR/(128): Failed to open file '/android.resource:/com.example.VideoTests/2130968576'. (No such file or directory)

如果我使用另一个uriString,它仍然会给出以下错误:

代码语言:javascript
运行
复制
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‘的简短内容,但同样的错误也会发生。

谢谢大家的帮助。

EN

Stack Overflow用户

回答已采纳

发布于 2013-02-03 02:10:01

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

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14574132

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档