Tecnologia do Blogger.
RSS

[androidbrasil-dev] Re: Fullscreen não está funcionando corretamente.

Desculpem a demora, mas retomei o projeto da TV e consegui resolver um dos problemas.


Em telas de densidade mdpi já consegui que fique ajustado ao fullscreen e problema onTouchEvent também foi corrigido depois de ajustar o  layout da maneira correta.

Porém estou com problema com versões Android 4.0+, pois quando estou tentando executar o código abaixo em fullscreen simplesmente ele mantem a tela preta e o aplicativo fica em loop. Um detalhe é que para versões inferiores a 4.0+ funciona normalmente.
Alguém já trabalhou com fullscreen ?

Em sexta-feira, 16 de novembro de 2012 11h13min20s UTC-3, Thalita Monteiro escreveu:
Bom dia gente,
Estou com duas situações em que o fullscreen não está funcionando corretamente.

- Primeira situação:

Estou realizando um teste no Samsung Galaxy S2 para exibir o meu vídeo através do videoview até ai ele funciona normalmente, mas quando clico para ele exibir em fullscreen ele dá o aviso: could not open file on client side, try server side. A versão do android desse aparelho é 4.1.2.  Alguém já passou por uma situação como essa?

- Segunda situação:

Realizando teste no Galaxy Ace para exibir o vídeo em fullscreen ocorre normalmente, porém quando o aparelho está em LANDSCAPE o OnTouchEvente não reconhece o click e não executa nenhuma ação.
Alguém já passou por isso?


Segue o meu código para ánalise:

AoVivo.java

public class AoVivo extends Activity implements OnCompletionListener, OnPreparedListener {
/* CABEÇALHO */
ImageView aovivo;
ImageView youtube;
ImageView facebook;
ImageView twitter;
ImageView sobre;
RelativeLayout cabecalho;
RelativeLayout viewAovivo;
/* IMAGEM INICIAL */
RelativeLayout imagemInicial;
ImageView streamIniciar;
/* STREAM */
RelativeLayout player;
VideoView video;
ImageView play;
ImageView fullscreen;
private LayoutParams padrao;
/* FULLSCREEN */
RelativeLayout media;
ImageView playFull;
ImageView screen;
SeekBar volume;
/* VOLUME */
RelativeLayout relVolume;
SeekBar volumeI;
/* PUBLICIDADE */
RelativeLayout rodape;
WebView publicidade;
/* CARREGAMENTO DO STREAM */
ProgressDialog load;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aovivo);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
/* EXIBINDO BACKGROUND DA APLICAÇÃO */
viewAovivo = (RelativeLayout) findViewById(R.aovivo.aovivo);
viewAovivo.setBackgroundResource(R.drawable.bg_geral);
/* EXIBINDO CABEÇALHO */
cabecalho = (RelativeLayout) findViewById(R.aovivo.cabecalho);
cabecalho.setVisibility(View.VISIBLE);
/* AO VIVO */
aovivo = (ImageView) findViewById(R.cabecalho.aovivo);
aovivo.setImageResource(R.drawable.bt_at_tp_aovivo);
/* YOUTUBE */
youtube = (ImageView) findViewById(R.cabecalho.youtube);
youtube.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent it = new Intent(AoVivo.this, Youtube.class);
startActivity(it);
finish();
}
});
/* FACEBOOK */
facebook = (ImageView) findViewById(R.cabecalho.facebook);
facebook.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent it = new Intent(AoVivo.this, Facebook.class);
startActivity(it);
finish();
}
});
/* TWITTER */
twitter = (ImageView) findViewById(R.cabecalho.twitter);
twitter.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent it = new Intent(AoVivo.this, Twitter.class);
startActivity(it);
finish();
}
});
/* SOBRE */
sobre = (ImageView) findViewById(R.cabecalho.sobre);
sobre.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent it = new Intent(AoVivo.this, Sobre.class);
startActivity(it);
finish();
}
});
/* IMAGEM INICIAL */
imagemInicial = (RelativeLayout) findViewById(R.aovivo.imagemInicial);
imagemInicial.setVisibility(View.VISIBLE);
streamIniciar = (ImageView) findViewById(R.aovivo.streamIniciar);
streamIniciar.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showTV();
}
});
/* STREAM */
player = (RelativeLayout) findViewById(R.aovivo.player);
play = (ImageView) findViewById(R.aovivo.play);
fullscreen = (ImageView) findViewById(R.aovivo.fullscreen);
video = (VideoView) findViewById(R.aovivo.video);
/* FULLSCREEN */
media = (RelativeLayout) findViewById(R.aovivo.media);
playFull = (ImageView) findViewById(R.aovivo.playRdp);
screen = (ImageView) findViewById(R.aovivo.fullscreenRdp);
volume = (SeekBar) findViewById(R.aovivo.volumeRdp);
/* RODAPÉ */
rodape = (RelativeLayout) findViewById(R.aovivo.rodape);
rodape.setVisibility(View.VISIBLE);
/* PUBLICIDADE */
publicidade = (WebView) findViewById(R.aovivo.publicidade);
publicidade.getSettings().setJavaScriptEnabled(true);
publicidade.getSettings().setPluginsEnabled(false);
publicidade.getSettings().setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);
publicidade.setWebViewClient(new MyWebClient());
publicidade.setBackgroundColor(0x00000000);
publicidade.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
if(isOnline()){
publicidade.loadUrl("linkpublicidade");
}
}
}
/* EXIBIR O PLAYER DA TV */
private void showTV(){
/* CARREGAR VÍDEO */
load = load.show(AoVivo.this, "", "Carregando...");
new Thread(){
@Override
public void run() {
try{
sleep(5000);
}catch (Exception e) {
Log.e("tag", e.getMessage());
}
}
};
/* ESCONDER IMAGENS INICIAIS*/
imagemInicial.setVisibility(View.GONE);
/* EXIBIR PLAYER E TV */
player.setVisibility(View.VISIBLE);
/* BOTÕES STREAM */
play.setImageResource(R.drawable.bt_pause);
play.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(video.isPlaying()){
            video.pause();
           } else {
            video.start();
           }
}
});
fullscreen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
/* ESCONDER VIEWS */
cabecalho.setVisibility(View.GONE);
rodape.setVisibility(View.GONE);
viewAovivo = null;
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
});
/* VOLUME */
volumeI = (SeekBar) findViewById(R.aovivo.volume);
final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
volumeI.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
volumeI.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
volumeI.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
public void onStopTrackingTouch(SeekBar arg0) {
}
public void onStartTrackingTouch(SeekBar arg0) {
}
public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1,0);
if(arg1 == 0) {
((ImageView) findViewById(R.aovivo.imgvolume)).setImageResource(R.drawable.bg_volume);
} else {
   ((ImageView) findViewById(R.aovivo.imgvolume)).setImageResource(R.drawable.bg_volume);
}
}
});       
/* CARREGANDO O VÍDEO */
video.setOnPreparedListener(AoVivo.this);
video.setOnCompletionListener(AoVivo.this);
video.setKeepScreenOn(true);
video.setVideoURI(Uri.parse("rtsp://stream"));
}
/* Abrir em uma nova aba o link da publicidade */
public class MyWebClient extends WebViewClient{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Uri uri = Uri.parse(url);
Context context = view.getContext();
Intent intent = new Intent(context,OpenSiteWebView.class);
Bundle parametros = new Bundle();
parametros.putString("url", url);
intent.putExtras(parametros);
startActivity(intent);
return true;
}
}
/* Verifica se está conectado */
private Boolean isOnline() {
    ConnectivityManager cm = 
     (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if(ni != null && ni.isConnected())
    return true;

    return false;
    }
public void onPrepared(MediaPlayer vp) {
if(video.canSeekForward()) video.seekTo(video.getDuration()/5);
video.start();
load.dismiss();
}

public void onCompletion(MediaPlayer mp) {
this.finish();
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(ev.getAction() == MotionEvent.ACTION_DOWN){
if(Configuration.ORIENTATION_LANDSCAPE == getScreenOrientation()){
if(video.isPlaying()){
/* EXIBINDO PARTES DA TELA */
            media.setVisibility(View.VISIBLE);
           
            playFull.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
        if(video.isPlaying()){
                    video.pause();
                   } else {
                    video.start();
                   }
        }
        });
           
            /* RETORNANDO DO FULLSCREEN */
            screen.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
});
           
            /* VOLUME FULLSCREEN */
            final AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
        volume.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC));
        volume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
        volume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
       
        public void onStopTrackingTouch(SeekBar arg0) {
        }
       
        public void onStartTrackingTouch(SeekBar arg0) {
        }
       
        public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1,0);
        if(arg1 == 0) {
        ((ImageView) findViewById(R.aovivo.imgvolume)).setImageResource(R.drawable.bg_volume);
        } else {
           ((ImageView) findViewById(R.aovivo.imgvolume)).setImageResource(R.drawable.bg_volume);
        }
        }
        });       
           
            video.pause();
           } else {
            media.setVisibility(View.GONE);
            video.start();
           }
}else{
if(video.isPlaying()){
            video.pause();
           } else {
            video.start();
           }
}
           
           return super.onTouchEvent(ev);
        } else {
           return true;
        }
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
padrao = video.getLayoutParams();
video.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}else{
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);
if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 
       Configuration.SCREENLAYOUT_SIZE_SMALL){
final float scale = video.getContext().getResources().getDisplayMetrics().density;
        int pixels = (int) (770 * scale + 0.5f);        
        params.width = pixels;
        pixels = (int) (200 * scale + 0.5f);
        params.height = pixels;
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
       
}else if((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 
       Configuration.SCREENLAYOUT_SIZE_NORMAL){
final float scale = video.getContext().getResources().getDisplayMetrics().density;
        int pixels = (int) (770 * scale + 0.5f);        
        params.width = pixels;
        pixels = (int) (500 * scale + 0.5f);
        params.height = pixels;
        params.addRule(RelativeLayout.ALIGN_PARENT_TOP,RelativeLayout.TRUE);
        params.addRule(RelativeLayout.CENTER_HORIZONTAL,RelativeLayout.TRUE);
}
       /* EXIBINDO AS VIEWS ESCONDIDAS E ESCONDENDO O FULLSCREEN */
media.setVisibility(View.GONE);
cabecalho.setVisibility(View.VISIBLE);
rodape.setVisibility(View.VISIBLE);
viewAovivo = (RelativeLayout) findViewById(R.aovivo.aovivo);
viewAovivo.setBackgroundResource(R.drawable.bg_geral);
video.setLayoutParams(params);
}
}
/* MANTENDO AS CONFIGURAÇÕES QUANDO A TELA MUDA DE POSIÇÃO */
public int getScreenOrientation(){
   Display getOrient = getWindowManager().getDefaultDisplay();
   int orientation = Configuration.ORIENTATION_UNDEFINED;
   if(getOrient.getWidth()==getOrient.getHeight()){
       orientation = Configuration.ORIENTATION_SQUARE;
   } else{ 
       if(getOrient.getWidth() < getOrient.getHeight()){
           orientation = Configuration.ORIENTATION_PORTRAIT;
       }else { 
            orientation = Configuration.ORIENTATION_LANDSCAPE;
       }
   }
   return orientation;
}

}

Aguardo uma resposta urgente.
--
Atenciosamente,
Thalita Monteiro Jorge.
Graduanda em Sistemas de Informação



    
"O importante é garantir os três pontos !"


--
 
 

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário