3

通过实施 Vitamio 库进行直播,努力为 G-Box 获得更好的质量。

代码中使用了具有 .mp4 视频的示例在线视频 URL。但是当我们下载后在媒体播放器中播放它时效果很好,当我通过在线流媒体尝试它时质量变得很差。

以下是在视频视图上播放视频的代码。

 public class VideoViewDemo extends Activity {

/**
 * TODO: Set the path variable to a streaming video URL or a local media file
 * path.
 */
private String path = "";
private VideoView mVideoView;
private ProgressDialog progDailog;
ProgressDialog progressDialog=null;

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.videoview);
    mVideoView = (VideoView) findViewById(R.id.surface_view);
    path = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
    if (path == "") {

        // Tell the user to provide a media file URL/path.
        Toast.makeText(VideoViewDemo.this, "Please edit
                     VideoViewDemo                Activity, and set path" + 
                " variable to your media file URL/path", Toast.LENGTH_LONG).show();
        return;
    } else {
        /*
         * Alternatively,for streaming media you can use
         * mVideoView.setVideoURI(Uri.parse(URLstring));
         */
        mVideoView.setVideoPath(path);
        mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();

        progDailog = ProgressDialog.show(this, "Please wait ...", 
           "Retrieving data ...", true);
        progDailog.setCancelable(true);


        mVideoView.setOnPreparedListener(
                new MediaPlayer.OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mediaPlayer) {
                // optional need Vitamio 4.0
                //mediaPlayer.setPlaybackSpeed(1.0f);
                  progDailog.dismiss();
            }
        });

        mVideoView.setOnBufferingUpdateListener(
                   new OnBufferingUpdateListener() {
            @Override
            public void onBufferingUpdate(MediaPlayer arg0, int arg1) {

            }
        });
        //mediaPlayer.setPlaybackSpeed(1.0f);
    }

}
@Override
protected void onPause() {
    mVideoView.pause();
    super.onPause();
}

@Override
protected void onResume() {
    mVideoView.resume();
    progDailog.show();
    super.onResume();

}
   }

您的即时回复将对我有很大帮助

4

2 回答 2

2

毫无疑问,Vitamio 是一个非常好的库,涵盖了与视频流相关的所有错误。

很抱歉,我对 Vitamio 支持团队感到非常失望。我在论坛上发布了问题,但没有收到和反馈。最后,我通过在提供的源上进行矿工更改来找到我的问题的解决方案。

enter code here@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
  WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    if (!LibsChecker.checkVitamioLibs(this))
        return;
    setContentView(R.layout.mediaplayer_2);
    mPreview = (SurfaceView) findViewById(R.id.surface);
    holder = mPreview.getHolder();
    holder.addCallback(this);
    //holder.setFormat(PixelFormat.RGBA_8888);
    holder.setFormat(PixelFormat.RGBX_8888);
    extras = getIntent().getExtras();
}

private void playVideo(Integer Media) {
    doCleanUp();
    Log.e(TAG, "Value Received: " + Media);
    try {

        switch (Media) {
        case LOCAL_VIDEO:
            /*
             * TODO: Set the path variable to a local media file path.
             */
            path = "";
 path = Environment.getExternalStorageDirectory() + "/big_buck_bunny.mp4";
            Log.e(TAG, "PATH = : " + path);
            if (path == "") {
                // Tell the user to provide a media file URL.
Toast.makeText(MediaPlayerDemo_Video.this, "Please edit MediaPlayerDemo_Video 
   Activity, " + "and set the path variable to your media file path." 
   + " Your media file must be stored on sdcard.", Toast.LENGTH_LONG).show();
                return;
            }
            break;
        case STREAM_VIDEO:
            /*
             * TODO: Set path variable to progressive streamable mp4 or
             * 3gpp format URL. Http protocol should be used.
             * Mediaplayer can only play "progressive streamable
         * contents" which basically means: 1. the movie atom has to
             * precede all the media data atoms. 2. The clip has to be
             * reasonably interleaved.
             * 
             */
            path = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4";
            if (path == "") {
                // Tell the user to provide a media file URL.
Toast.makeText(MediaPlayerDemo_Video.this, "Please edit MediaPlayerDemo_Video 
    Activity," + " and set the path variable to your media file URL.", 
   Toast.LENGTH_LONG).show();
                return;
            }

            break;

        }
        // Create a new media player and set the listeners

        mMediaPlayer = new MediaPlayer(this);
mMediaPlayer.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);            
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
    mMediaPlayer.prepare();                         
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.getMetadata();
        setVolumeControlStream  
 (AudioManager.STREAM_MUSIC);           
        //mMediaPlayer.setVideoQuality
 (io.vov.vitamio.MediaPlayer.VIDEOQUALITY_HIGH);


    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}

示例源中有一个名为“MediaPlayerDemo_Video.java”的文件替换以下行 holder.setFormat(PixelFormat.RGBA_8888);

有以下

holder.setFormat(PixelFormat.RGBX_8888);

这将解决整个问题。

于 2013-10-28T15:50:29.793 回答
2

我使用这个库的视频质量是低视频和播放模糊视频。现在我在我的视频播放器类中使用了以下方法。您可以在加载视频 URL 后使用此方法。

public void init() {
    load = (ProgressBar) this.findViewById(R.id.load);
    empty = (TextView) this.findViewById(R.id.empty);

    mVideoView = (VideoView) this.findViewById(R.id.surface_view);
    mVideoView.setVideoQuality(MediaPlayer.VIDEOQUALITY_HIGH);

    holder = mVideoView.getHolder();
    holder.setFormat(PixelFormat.RGBX_8888);

    mVideoView.setMediaController(new MediaController(this));
    mVideoView.setOnCompletionListener(this);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setOnErrorListener(this);

    Uri videoUri = Uri.parse(url);

    mVideoView.setVideoURI(videoUri);
    mVideoView.requestFocus();

    loading();
}  
于 2014-07-07T11:18:33.160 回答