android media player not working

孤街醉人 提交于 2019-12-22 18:27:24

问题


I'm trying to develop an app that has many videos embedded in it, and I'd like to call Android's Media Player, with the video on VideoView object. However, i get these strange errors:

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

when i try to play a mp4 video, or another 3gp video that is not recorded from my phone. My code is something like:

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

    }
}
}

and my layout is something like:

<?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>

Is there something wrong with my code?

and i know that my file is there and all. I've run this code with a sample 3GP video and it worked just fine (but i recorded the video from my phone and copied it to my computer and then re-packaged in to my app, under the /res/raw folder in Eclipse). However, The problem is that for some reason, my media player only plays certain 3GPP files. If i try to convert a MP4 to 3GP using MobileMediaConverter, it plays on my laptop but not in this app. Also note that if i open the video as a file (in other words, invoking the default video player on my Samsung Galaxy S phone) it works just fine (meaning my phone has the capabilities). So i'm wondering:

  • is this something wrong with the code?
  • is this more of a converting mp4 to 3gp error?

Any help would be greatly appreciated. Thanks!!


回答1:


The problem was the certain converters (with different settings) will create a video file that doesn't run on my Samsung Galaxy android device. the code here is generic, but i think the codec has to be something like H.264 when doing the video conversion. I then downloaded about 5 video converters and 2 of them will actually make a 3GPP that my device can play. so if anyone else has this problem, i would recommend trying a bunch of video converters, with different codec/audio settings. i was eventually able to find one that worked in my particular case



来源:https://stackoverflow.com/questions/6159518/android-media-player-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!