Vitamio SDK,视频和音频滞后
Vitamio SDK, Video and Audio lagging
我在我的应用程序中使用 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 + "%");
}
}
如果您遇到 "LAGGING" 问题,那是由 Android 模拟器引起的。
我在模拟器设置中使用了 2GB 内存,由于某些原因,Vitamio 在 Android 模拟器中播放视频时出现一些问题。
尝试在真实设备上执行此操作,此问题将会或应该消失。
我在我的应用程序中使用 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 + "%");
}
}
如果您遇到 "LAGGING" 问题,那是由 Android 模拟器引起的。
我在模拟器设置中使用了 2GB 内存,由于某些原因,Vitamio 在 Android 模拟器中播放视频时出现一些问题。
尝试在真实设备上执行此操作,此问题将会或应该消失。