java - VideoView 和 MediaPlayer 错误(1、-2147483648)

标签 java android xml media android-videoview

我正在尝试使用 VideoView 从 SD 卡运行视频。但LogCat仍然显示相同的错误

错误 (1-2147483648)

可以是什么?我缺少任何权限或其他什么?

我的代码是:

Java

package com.example.videoview;

import android.app.Activity; import android.os.Bundle; import
android.widget.MediaController; import android.widget.VideoView;


public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        VideoView vid = (VideoView) findViewById(R.id.videoView);

        vid.setVideoPath("/sdcard/MeuFilme.mp4");
        vid.setMediaController(new MediaController(this));
        vid.start();
        vid.requestFocus();

    }


}

布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.videoview.MainActivity" >

<VideoView
    android:id="@+id/videoView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" />

list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videoview"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="19" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

最佳答案

VideoView 在低于 Jelly Bean、Api 级别 16、Android 4.1 for api < 16 的版本中存在错误,VideoView 无法读取写入磁盘的文件,因为它在与应用程序不同的上下文中读取这些文件,因此不会有正确的许可。您可以获取文件描述符并将其传递给VideoView

VideoView 的 onError 回调中是这样的

文件 file = new File("/sdcard/MeuFilme.mp4"); 输入流 = new FileInputStream(file); mediaPlayer.setDataSource(inputStream.getFD());

关于java - VideoView 和 MediaPlayer 错误(1、-2147483648),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25696237/

相关文章:

java - JAXB、带有 @XmlID 注释的 XML mashal

java - NoSuchBeanDefinitionException : No qualifying bean

java - ArrayList 调整当前底层数组的大小或创建一个新数组?

java - JScrollPane 使我的 JList 单元格的宽度属性无效

java - 我无法在Android Studio上运行该应用程序

java - 为什么 'BackgroundFetchHeadlessTask.java' 在 ionic 中不起作用?

java - 在 Heroku 上运行 maven 项目会出现应用程序错误

Java:带有 SimpleCursorAdapter 的 ORMLite:StaleDataException

android - Fragment BackStack 无法正常工作

c# - XMLDocument.Load(url) 通过代理