简体   繁体   English

VideoView和MediaPlayer错误(1,-2147483648)

[英]VideoView and MediaPlayer error(1, -2147483648)

I'm trying to run a video from sdcard using VideoView. 我正在尝试使用VideoView从sdcard运行视频。 But LogCat is still showing the same error 但是LogCat仍然显示相同的错误

Error (1-2147483648) 错误(1-2147483648)

What can be? 可以是什么? I'm missing any permission or something else? 我缺少任何许可或其他东西吗?

My code is: 我的代码是:

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();

    }


}

Layout 布局

<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" />

Manifest 表现

<?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 has a bug in versions lower than Jelly Bean, Api Level 16, Android 4.1 for api < 16, VideoView is not able to read files written to disk since it reads them in a Context different from the Application and therefore does not have correct permission. VideoView在低于Jelly Bean,Api Level 16,低于api <16的Android 4.1的版本中存在错误,VideoView无法读取写入磁盘的文件,因为它在与应用程序不同的上下文中读取它们,因此没有正确的权限。 You can obtain file descriptor and pass it to VideoView 您可以获取文件描述符并将其传递给VideoView

Smth like this in VideoView's onError callback VideoView的onError回调中类似这样的内容

File file = new File("/sdcard/MeuFilme.mp4"); InputStream is = new FileInputStream(file); mediaPlayer.setDataSource(inputStream.getFD());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM