VideoView in eclipse not playing on phone

我的梦境 提交于 2019-12-02 11:06:16

问题


I put a videoview in eclipse for an android app but the video will not play on my phone.

package test.test;

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


public class graphics extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    VideoView videoView = (VideoView) findViewById(R.id.test);
    MediaController mediaController = new MediaController (this);
    mediaController.setAnchorView(videoView);
    Uri video = Uri.parse("http://commonsware.com/misc/test2.3gp");
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(video);
    videoView.start();

    }
} 

回答1:


I think problem lies either with connectivity (http) or VideoView usage.

To know if the connectivity is the issue, you can try playing media content local to the phone, i.e. from SD Card.

Issues also be coming from VideoView usage

VideoView class uses SurfaceView and MediaPlayer to achieve Video Playback. MediaPlayer has APIs to set url, prepare the media pipeline, start the pipeline etc. But before pipeline can be started; the pipeline has to be ready i.e. in preroll condition. To notify application about this, MediaPlayer provides listeners. In this case it is onPrepareListener. VideoView which interacts with MediaPlayer also (has to ?) provides these listeners as well.

Have a look below code for VideoPlayer activity which uses VideoView for playback. (Verified for local content only) This activity takes absolute path to file to be played from intent. (passed from list activity)

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnPreparedListener;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.VideoView;


public class VideoPlayer extends Activity implements OnCompletionListener, OnPreparedListener {
    private static VideoView vView;
    private String filePath;
    public static long clipDurationMS; 
    private View        mLoadingIndicator; 

    public void onCreate(Bundle savedInstanceState)     
    {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        vView = (VideoView)findViewById(R.id.VideoView01);
        mLoadingIndicator = findViewById(R.id.progress_indicator); 

        vView.setBackgroundColor(0x0000); 

        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        filePath = (String)extras.get("URL");

        vView.setVideoPath(filePath);  

        MediaController mc;
        mc = new MediaController(this);
        vView.setMediaController(mc);

        vView.requestFocus();
        vView.setOnCompletionListener(this);
        vView.setOnPreparedListener(this);
    }

    public void onCompletion(MediaPlayer arg0) 
    {
        finish();   
    }

    public void onPrepared(MediaPlayer arg0) 
    {
        mLoadingIndicator.setVisibility(View.GONE);
        ViewGroup.LayoutParams params;

        params        = vView.getLayoutParams();

        params.height = arg0.getVideoHeight();
        params.width  = arg0.getVideoWidth();

        vView.setLayoutParams(params);

        vView.start(); 
    }

    public void onStop(){
        super.onStop();
        vView.stopPlayback();
        finish();
    }
}

Shash




回答2:


Check whether your phone is connected to an Internet connection or not. In my view that might be a problem because you are trying to play a video from an Uri.



来源:https://stackoverflow.com/questions/6977382/videoview-in-eclipse-not-playing-on-phone

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