Android媒体播放器无法正常工作

时间:2011-05-28 03:44:04

标签: android android-mediaplayer android-videoview

我正在尝试开发一个嵌入了许多视频的应用,我想通过VideoView对象上的视频调用Android的媒体播放器。但是,我得到了这些奇怪的错误:

  • I / MediaPlayer(2874):Info(1,26)
  • E / MediaPlayer(2874):错误(-4,-4)
  • D / VideoView(2874):错误:-4,-4

当我尝试播放mp4视频或其他3gp视频时,我的手机没有录制。我的代码类似于:

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

public class PlayTest2 extends Activity{
private MediaController ctlr;
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test2);

    try {
        VideoView video = (VideoView) findViewById(R.id.test2);
        // Load and start the movie
                video.setVideoPath("android.resource://com.example.child.protector/raw/output");
        ctlr=new MediaController(this);
        ctlr.setMediaPlayer(video);
        video.setMediaController(ctlr);
        video.start();
        //video.requestFocus();//this line is new
    }
    catch (Exception e) {
       Log.e("---------- this is my app --------", "error: " + e.getMessage(), e);

    }
}
}

我的布局就像:

<?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/test2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
/>
</FrameLayout>

我的代码有问题吗?

我知道我的档案就在那里。我使用示例3GP视频运行此代码,它工作得很好(但我从手机录制视频并将其复制到我的计算机,然后重新打包到我的应用程序,在Eclipse中的/ res / raw文件夹下)。然而,问题是由于某种原因,我的媒体播放器只播放某些3GPP文件。如果我尝试使用MobileMediaConverter将MP4转换为3GP,它会在我的笔记本电脑上播放但不会在此应用中播放。另请注意,如果我将视频作为文件打开(换句话说,在我的三星Galaxy S手机上调用默认视频播放器)它可以正常工作(意味着我的手机具有这些功能)。所以我想知道:

  • 代码有问题吗?
  • 这更像是一个转换mp4到3gp的错误?

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

问题是某些转换器(具有不同的设置)将创建一个不在我的Samsung Galaxy Android设备上运行的视频文件。这里的代码是通用的,但我认为编解码器在进行视频转换时必须像H.264一样。然后我下载了大约5个视频转换器,其中2个实际上将制作我的设备可以播放的3GPP。所以,如果其他人有这个问题,我建议尝试一堆视频转换器,具有不同的编解码器/音频设置。我最终能够找到一个在我的特定情况下工作的

相关问题