我有一个项目,其中播放了 IPTV 。我想确定是否有视频信号,以便在没有信号时显示警报对话框。我可以设置一个计时器来等待信号返回,但是我不知道如何识别是否有信号。请你帮助我好吗。我留下了我正在使用的代码。 SdkVersion 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());
}
}