4

我正在关注在 Android 中播放视频的教程, 教程在这里

但是当我在模拟器上运行应用程序时,它给了我以下错误

媒体播放器错误 (1, -2147483648)

请帮忙

这是我的应用程序的代码

JAVA

package com.example.videoplayer;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnErrorListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.graphics.PixelFormat;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.Toast;
import android.widget.VideoView;

public class MainActivity extends Activity {

    public static String url = "rtsp://v3.cache8.c.youtube.com/CiILENy73wIaGQmXovF6e-Rf-BMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp";
    private VideoView videoView = null;
    private ProgressBar prog = null;
    private Context ctx = null;
    private MediaController mediaController = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setFormat(PixelFormat.TRANSLUCENT);
        setContentView(R.layout.activity_main);

        ctx = this;
        prog = (ProgressBar) findViewById(R.id.prog);
        videoView = (VideoView) findViewById(R.id.video);
        Uri video = Uri.parse(url);
        mediaController = new MediaController(this);
        mediaController.setAnchorView(videoView);
        videoView.setMediaController(mediaController);
        videoView.setVideoURI(video);

        videoView.setOnErrorListener(new OnErrorListener(){
            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            Toast.makeText(ctx, "Error occured", 500).show();
            return false;
            }
        });

        videoView.setOnPreparedListener(new OnPreparedListener(){
            @Override
            public void onPrepared(MediaPlayer arg0) {
                // TODO Auto-generated method stub
                prog.setVisibility(View.GONE);
                videoView.start();
            }
        });
    }

    @Override
    protected void onDestroy(){
        try{
            videoView.stopPlayback();
        }
        catch(Exception e)
        {
            Log.d("MideoPlayer", "Error OnDestroy");
        }
        super.onDestroy();
    }

}

XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
    <FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <VideoView
        android:id="@+id/video"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"/>
        <ProgressBar
        android:id="@+id/prog"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_gravity="center"/>
    </FrameLayout>
</LinearLayout>

和清单

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.videoplayer.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>

</manifest>
4

1 回答 1

1

在此处添加此作为答案以帮助其他人解决此问题-我看到此错误主要仅发生在模拟器上,并且似乎在设备上运行良好。可能是模拟器设置问题,如果我发现任何官方报告的问题,我将更新此线程。如果我尝试播放不受支持的格式(如 wmv),我只会在设备上看到这种情况。如果有人在模拟器上有此问题的链接,请添加

于 2013-07-21T06:17:08.487 回答