其他分享
首页 > 其他分享> > 使用Vitamio Library的电视盒上的Android VideoView质量太差了

使用Vitamio Library的电视盒上的Android VideoView质量太差了

作者:互联网

通过实施Vitamio库进行实时流式传输,努力为G-Box提供更好的质量.

在代码中使用了具有.mp4视频的示例在线视频URL.但是当我们在下载后在Media Player中播放它时,效果很好,而当我通过在线流进行尝试时,质量会很差.

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

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

}
   }

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

解决方法:

毫无疑问,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);

这将解决整个问题.

标签:video,video-streaming,android-videoview,vitamio,android
来源: https://codeday.me/bug/20191030/1966595.html