由于VideoView错误,无法播放此视频

问题描述 投票:1回答:2

我正试图在我的Android应用中播放视频作为启动画面。我已经搜索了很多有关VideoView问题的教程和响应者,但我不知道该怎么办...

我尝试使用硬编码链接到我的SD卡(/sdcard/filename.mp4),我尝试使用Environment.getExternalStorageDirectory(),我尝试使用我的应用程序(R.raw.filename)中的文件夹中的视频,似乎没有任何工作。我得到一个黑屏或一条我无法播放此视频的消息......

对于我尝试使用各种视频格式的所有方法(所有这些格式都支持Android)

这是我的Java代码:

package com.example.android;

import android.app.Activity;
import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;

public class SplashScreen extends Activity implements OnClickListener {



protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fragment_splash);

    String path = Environment.getExternalStorageDirectory() + "/splash.mp4";
    VideoView vid =(VideoView)findViewById(R.id.videoView1);
    vid.setVideoURI(Uri.parse(path));
    vid.setMediaController(new MediaController(this));
    vid.start();
    vid.requestFocus();
}





@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.pocetna, menu);
    return true;
}



/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_splash,
                container, false);
        return rootView;
    }

}



@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}






}

我的XML:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<VideoView
    android:id="@+id/videoView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</FrameLayout>
java android video android-video-player
2个回答
3
投票

在清单中添加这个对我有用:

android.permission.READ_EXTERNAL_STORAGE

0
投票

我不确定但是你可能需要代替vid.setVideoURI(Uri.parse(path)); vid.setVideoPath( “/ SD卡/ splash.mp4”);?

或许你找到答案:Playing a video in VideoView in Android

© www.soinside.com 2019 - 2024. All rights reserved.