验证 videoview 中是否有视频信号

Verify if there is video signal in videoview

我有一个播放 IPTV 的项目。我想确定是否有视频信号,以便在没有信号时显示警报对话框。我可以设置一个计时器等待信号到return,但我不知道如何识别是否有信号。请你帮助我好吗。我留下了我正在使用的代码。 SDK 版本 22.

public class Television extends Activity {

VideoView videoView;
ImageView volmas, volmenos, voloff;
SeekBar seekbar;
TextView textview, tvvolumen;
AudioManager audioManager;
int i = 50;
int volumen = 7;
int volumenporcentaje;
Toast toast;
Exception e;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_television);

    try {
        String canal = getIntent().getStringExtra("Canal");

        volmas = (ImageView) findViewById(R.id.volmas);
        volmenos = (ImageView) findViewById(R.id.volmenos);
        voloff = (ImageView) findViewById(R.id.voloff);

        tvvolumen = (TextView) findViewById(R.id.tvvolumen);
        volumenporcentaje = (volumen * 100) / 15;
        tvvolumen.setText("" + volumenporcentaje + "%");

        e = null;

        videoView = (VideoView) this.findViewById(R.id.videoViewTV);
        videoView.setVideoURI(Uri.parse(canal));
        videoView.requestFocus();
        videoView.start();

        voloff.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                volumen = 0;
                audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumen, 0);
                volumenporcentaje = (volumen * 100) / 15;
                tvvolumen.setText("" + volumenporcentaje + "%");
            }
        });

        volmas.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (volumen < 15) {
                    volumen = volumen + 1;
                    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumen, 0);
                    volumenporcentaje = (volumen * 100) / 15;
                    tvvolumen.setText("" + volumenporcentaje + "%");
                }
                if (volumen >= 15) {
                    Toast.makeText(Television.this, "Volumen al máximo", Toast.LENGTH_SHORT).show();
                }
            }
        });

        volmenos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (volumen > 0) {
                    volumen = volumen - 1;
                    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumen, 0);
                    volumenporcentaje = (volumen * 100) / 15;
                    tvvolumen.setText("" + volumenporcentaje + "%");
                }
                if (volumen == 0) {
                    Toast.makeText(Television.this, "Volumen al mínimo", Toast.LENGTH_SHORT).show();
                }
            }
        });

        seekbar = (SeekBar) findViewById(R.id.seekBar1);
        audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

        seekbar.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volumen, 0);
    } catch (Exception e) {
        Errores.exception(e, this.getApplicationContext());
    }
}

我建议你改变你的做法!使用 Exomedia or Exoplayer 库。它们很简单。

根据您的选择,您可以使用它们的功能来解决您的问题:)