[RESOLVIDO] Problema full screen em Android 4.0+

Boa tarde,
Estou com o seguinte problema: possuo uma aplicação que exibe um stream de vídeo e preciso que o usuário tenha a possibilidade de alterar entre a tela cheia(fullscreen) e a tela “normal”. Estou conseguindo fazer isso em versões de Android 2.0+, porém quando eu tento executar em versões 4.0+ o fullscreen simplesmente fica com uma tela preta e parece ficar em loop. Ah! Vale lembrar que ele não apresenta nenhum erro. Fica na tela preta por horas e não saí mais disso.

Alguém já passou por alguma situação semelhante ou sabe me dizer se as versões 4.0+ tem alguma diferença em tratar stream de videos?

Segue o meu código:

[code]public class AoVivo_ extends Activity implements OnCompletionListener,
OnPreparedListener, OnVideoSizeChangedListener {

/* 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;

/* TAMANHO DA TELA */
private int screen_width, screen_height;
private int media_width, media_height;
private boolean landscape;
private final String TAG = "HelloInterruptVideoStream";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.aovivo);
    
    if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
        
        /* EXIBINDO BACKGROUND DA APLICAÇÃO */
        viewAovivo = (RelativeLayout) findViewById(R.aovivo.aovivo);
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            viewAovivo.setBackgroundResource(R.drawable.bg_geral); 
        }
        
        /* EXIBINDO CABEÇALHO */
        cabecalho = (RelativeLayout) findViewById(R.aovivo.cabecalho);
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            cabecalho.setVisibility(View.VISIBLE);
        }
        
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            /* 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();
                }
            });
        }
        /* Get the size of the device, will be our maximum. */
        Display display = getWindowManager().getDefaultDisplay();
        screen_width = display.getWidth();
        screen_height = display.getHeight();
        
        
        /* IMAGEM INICIAL */
        imagemInicial = (RelativeLayout) findViewById(R.aovivo.imagemInicial);
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            imagemInicial.setVisibility(View.VISIBLE);
        }
        
        streamIniciar = (ImageView) findViewById(R.aovivo.streamIniciar);
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            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);
        if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
            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("http://banners.xxx.com.br/xxxx/www/xxx/afr.php?zoneid=xxx");
        }
        
    }
        

}

/* 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://xxx.zoeweb.xx/xxx-live/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) {
    /* DIMENSÕES */
    final DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    final int density = metrics.densityDpi;
    
     if(video.canSeekForward()) video.seekTo(video.getDuration()/5);
     video.start();
     
     if(DisplayMetrics.DENSITY_LOW != density){
         resize();
     }
     
     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()){
                    
            /* EXIBINDO PARTES DA TELA */
            media.setVisibility(View.VISIBLE);
            
            if(video.isPlaying()){
                
                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);
                        resize();
                    }
                });
                
                /* 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);
    
    landscape = (Configuration.ORIENTATION_LANDSCAPE == newConfig.orientation);
    resize();
}

public void resize() {
    int w = landscape ? screen_height : screen_width;
    int h = landscape ? screen_width : screen_height;
    
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);

    // If we have the media, calculate best scaling inside bounds.
    if (media_width > 0 && media_height > 0) {
        final float max_w = w;
        final float max_h = h;
        float temp_w = media_width;
        float temp_h = media_height;
        float factor = max_w / temp_w;
        temp_w *= factor;
        temp_h *= factor;

        // If we went above the height limit, scale down.
        if (temp_h > max_h) {
            factor = max_h / temp_h;
            temp_w *= factor;
            temp_h *= factor;
        }

        w = (int) temp_w;
        h = (int) temp_h;
    }
    //video.setDimensions(w, h);
    
    if(getScreenOrientation() == Configuration.ORIENTATION_LANDSCAPE){
        
        params.width = w;
        params.height = h;
        params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        params.topMargin = 5;
        
        viewAovivo.setBackgroundColor(getResources().getColor(R.color.preto));
        video.setLayoutParams(params);
        video.getHolder().setFixedSize(w, h);

    }else{
        
        /* DIMENSÕES */
        final DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        final int density = metrics.densityDpi;
        
        params.width = w;
        
        if(DisplayMetrics.DENSITY_LOW == density){
            params.height = 151;
        }else if(DisplayMetrics.DENSITY_MEDIUM == density){
            params.height = 230;
        }else if(DisplayMetrics.DENSITY_HIGH == density){
            params.height = 300;
        }
        
        video.setLayoutParams(params);
        video.getHolder().setFixedSize(w, h);
        
        viewAovivo.setBackgroundResource(R.drawable.bg_geral);
        media.setVisibility(View.GONE);
        cabecalho.setVisibility(View.VISIBLE);
        rodape.setVisibility(View.VISIBLE);
    }
}

public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
    media_width = width;
    media_height = height;
    Log.i(TAG, "onVideoSizeChanged " + media_width + "x" + media_height);

    if (media_width > 0 && media_height > 0) {
        resize();
        video.start();
        mp.setOnVideoSizeChangedListener(null);
    }
}

/* 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;
}

}[/code]

A melhor maneira desenhar vídeo é em uma superfície opengl es. Essa superfície executa diretamenta na plaquinha aceleradora do dispositivo. Usando isso você evita esse tipo de comportamento em determinados componentes por falta de processamento, memória do dispositivo ou perda de sincronismo.


http://developer.android.com/training/graphics/opengl/index.html

Ainda não conseguir solucionar.

Alguém ?

@juliocbq, dei uma longa pesquisada sobre o que você falou, mas não consegui encontrar nada satisfatório. :cry:

Boa tarde gente,
Conseguir chegar até o SurfaceView e com ele consegui fazer com que os dispositivos com versões entre a 2.0+ até 4.0+ conseguissem executar e também deixar a tela em fullscreen, porém o SurfaceView quando é colocado antes de outros widget, como um ImageView ou Button, o SurfaceView sobrepões e fica em tela cheia.
Já tentei ajustando tanto no layout XML quanto via programação: setFixedSize(176, 144);, mas nada funcionou.

Alguém sabe como deixar ele com o tamanho que eu quero?

Eu coloco o video numa SurfaceView dentro de um FramelLayout.

Seto o tamanho do FrameLayout e deixo a view interna CENTER, ele até coloca aquelas barrinhas pretas sem esticar o conteudo.

isso do video sobrepor outros componentes é problema nativo do android que sempre tenta deixar as midias a frente de tudo, tendo que tomar cuidado no xml para deixar o videoView no “topo”

Muito obrigada pelas dicas!
Com a dica do Mark consegui fazer o que queria, porém estou com problema que o onTouchEvent não está funcionando direito.
Ele simplesmente não reconhece quando o aplicativo está em tela cheia.
Será que o framelayout tem algum impecilho em relação a isso?

@Override
	public boolean onTouchEvent(MotionEvent ev) {
		
		if(ev.getAction() == MotionEvent.ACTION_DOWN){
			if(Configuration.ORIENTATION_LANDSCAPE == getScreenOrientation()){
						
				/* EXIBINDO PARTES DA TELA */
				playFull.setVisibility(View.VISIBLE);
				
				if(mediaPlayer.isPlaying()){
	            	
	            	playFull.setOnClickListener(new View.OnClickListener() {
	        			public void onClick(View v) {
	        				if(mediaPlayer.isPlaying()){
	        					mediaPlayer.pause();
	        	            } else {
	        	            	playFull.setVisibility(View.INVISIBLE);
	        	            	mediaPlayer.start();
	        	            }
	        			}
	        		});
	            	
	            	/* RETORNANDO DO FULLSCREEN */
	            	screen.setOnClickListener(new View.OnClickListener() {
						public void onClick(View v) {
							setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
							resize();
						}
					});
	            	
	            	
	            	
	            	mediaPlayer.pause();
	            } else {
	            	media.setVisibility(View.GONE);
	            	mediaPlayer.start();
	            }
				
			}else{
				if(mediaPlayer.isPlaying()){
					mediaPlayer.pause();
	            } else {
	            	mediaPlayer.start();
	            }
			}
           
           return super.onTouchEvent(ev);		
        } else {
           return true;		
        }
	}

E o meu XML tá assim:

 <!-- SURFACE -->

    <FrameLayout
        android:id="@+face/showVideo"
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:layout_below="@+face/playInicial"
        android:clickable="true" >

        <!-- PLAYER FULLSCREEN -->

        <RelativeLayout
            android:id="@+face/fullPlay"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="#AA000000"
            android:visibility="invisible" >

            <ImageView
                android:id="@+face/bt_play_"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <ImageView
                android:id="@+face/fullscreen_"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@+stream/bt_play"
                android:paddingLeft="3dp"
                android:src="@drawable/ic_launcher" />
        </RelativeLayout>

        <SurfaceView
            android:id="@+face/video"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" />
    </FrameLayout>

Boa tarde,
Finalmente consegui resolver o meu problema com fullscreen para diversos tamanho de tela.
Para conseguir o resultado esperado tive que utilizar o SurfaceView para exibir o stream do vídeo que eu desejava e ir fazendo a adaptação de acordo com as minhas necessidades.
Segue o link para quem quiser dar uma pesquisada e está precisando: http://android-er.blogspot.com.br/2012/03/play-media-on-surfaceview-using.html

Problema resolvido.