我在我的应用中使用Vitamio SDK来播放实时流。 它确实发挥,但它喜欢慢动作,首先想到的是,慢速的互联网连接..增加缓冲区大小,并将视频质量改为低。
但仍然如此。 任何人都可以帮助我吗?
这是我的代码:
package com.example.asd;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import io.vov.vitamio.LibsChecker;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.MediaPlayer.OnBufferingUpdateListener;
import io.vov.vitamio.MediaPlayer.OnInfoListener;
import io.vov.vitamio.utils.StringUtils;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
public class VideoBuffer extends AppCompatActivity implements OnInfoListener, OnBufferingUpdateListener {
private String path = "rtmp://stream.smcloud.net/live2/eska_party/eska_party_360p";
private VideoView mVideoView;
private ProgressBar pb;
private TextView downloadRateView;
private TextView loadRateView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!LibsChecker.checkVitamioLibs(this))
return;
setContentView(R.layout.activity_video_buffer);
mVideoView = (VideoView) findViewById(R.id.buffer);
pb = (ProgressBar) findViewById(R.id.probar);
downloadRateView = (TextView) findViewById(R.id.download_rate);
loadRateView = (TextView) findViewById(R.id.load_rate);
if (path == "") {
// Tell the user to provide a media file URL/path.
Toast.makeText(
VideoBuffer.this,
"Please edit VideoBuffer 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));
*/
/*uridec = Uri.parse(path);*/
/*mVideoView.setVideoURI(uri);*/
mVideoView.setVideoURI(Uri.parse(path));
//mVideoView.setVideoURI(path);
mVideoView.setMediaController(new MediaController(this));
mVideoView.setOnInfoListener(this);
mVideoView.setOnBufferingUpdateListener(this);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
// optional need Vitamio 4.0
mediaPlayer.setPlaybackSpeed(1.0f);
mediaPlayer.setBufferSize(1024 * 10);
mediaPlayer.setVideoQuality(MediaPlayer.VIDEOQUALITY_LOW);
mVideoView.requestFocus();
}
});
}
}
@Override
public boolean onInfo(MediaPlayer mp, int what, int extra) {
switch (what) {
case MediaPlayer.MEDIA_INFO_BUFFERING_START:
if (mVideoView.isPlaying()) {
mVideoView.pause();
pb.setVisibility(View.VISIBLE);
downloadRateView.setText("DR" + extra + "kb/s" + " ");
Log.e("PRIVPLAYERLOGS", "buff update " + extra + "kb/s");
loadRateView.setText("LR" + extra + "kb/s" + " ");
downloadRateView.setVisibility(View.VISIBLE);
loadRateView.setVisibility(View.VISIBLE);
}
break;
case MediaPlayer.MEDIA_INFO_BUFFERING_END:
mVideoView.start();
pb.setVisibility(View.GONE);
downloadRateView.setVisibility(View.GONE);
loadRateView.setVisibility(View.GONE);
break;
case MediaPlayer.MEDIA_INFO_DOWNLOAD_RATE_CHANGED:
downloadRateView.setText("" + extra + "kb/s" + " ");
Log.e("PRIVPLAYERLOGS", "buff update " + extra + "kb/s");
break;
}
return true;
}
@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
loadRateView.setText(percent + "%");
Log.e("PRIVPLAYERLOGS", "buff update "+ percent + "%");
}
}
答案 0 :(得分:0)
如果遇到“LAGGING”问题,则由Android模拟器引起。
我在模拟器设置中使用2GB内存,由于某些原因,Vitamio通过播放视频在Android模拟器中遇到了一些问题。
尝试在真实设备上执行此操作,此问题将会或应该消失。