2010-12-10 5 views
2

두 개의 탭에 각각 videoView가 포함되어 있습니다. 그러나 비디오가 재생되는 두 번째 탭으로 전환하면 오디오가 작동하지만 비디오가 재생되지 않고보기가 검정색으로 표시됩니다.탭을 전환 할 때 VideoView에 동영상이 표시되지 않습니다.

TabActivity :

package com.example.tab; 


import android.app.TabActivity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.widget.TabHost; 

public class main extends TabActivity { 
    /** Called when the activity is first created. */ 

private TabHost tabHost; 

public void onCreate(Bundle savedInstanceState){ 
super.onCreate(savedInstanceState); 
tabHost = getTabHost(); 

    Intent intent1 = new Intent(this, Video1.class); 
    Intent intent2 = new Intent(this, Video2.class); 


    tabHost.addTab(tabHost.newTabSpec("Tab1") 
     .setIndicator("Video1") 
     .setContent(intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP))); 

    tabHost.addTab(tabHost.newTabSpec("Tab2") 
    .setIndicator("Video2") 
    .setContent(intent2.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP))); 

} 
} 

비디오 1 활동

/** 
* 
*/ 
package com.example.tab; 

import android.app.Activity; 

import android.content.Intent; 
import android.content.res.Configuration; 

import android.net.Uri; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.SurfaceHolder; 
import android.view.View; 

import android.widget.MediaController; 
import android.widget.VideoView; 

/** 
* @author lyubomir.todorov 
* 
*/ 
public class Video1 extends Activity implements SurfaceHolder.Callback { 

private String path = "http://xxx.xxx"; 

private VideoView mVideoView; 

private SurfaceHolder holder; 
private static final int INSERT_ID = Menu.FIRST; 
private static final String TAG = "Tab"; 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.videoview1); 

    mVideoView = (VideoView) findViewById(R.id.surface_view1); 
// holder = mVideoView.getHolder(); 
// holder.addCallback(this); 
// holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); 

} 

     public boolean onCreateOptionsMenu(Menu menu) { 
    super.onCreateOptionsMenu(menu); 
    menu.add(0, INSERT_ID, 0, "FullScreen"); 

    return true; 
} 

public boolean onOptionsItemSelected(MenuItem item) { 
    Log.d(TAG, "Player re-started after device configuration change"); 

    return true; 
} 

@Override 
public void onConfigurationChanged(Configuration newConfig) { 
    super.onConfigurationChanged(newConfig); 
} 

@Override 
protected void onResume() { 
    // TODO Auto-generated method stub 
    super.onResume(); 

    PlayVideo(); 

    Log.d(TAG, "onResume Video1"); 

} 

protected void onPause() { 
    super.onDestroy(); 
    Log.d(TAG, "onPause Video1"); 
    if (mVideoView != null) { 
    mVideoView.stopPlayback(); 
    mVideoView.setVisibility(View.GONE); 
    mVideoView=null; 
    Log.d(TAG, "onPause1 Video1"); 
    } 

} 



public void surfaceDestroyed(SurfaceHolder surfaceholder) { 
    holder.isCreating(); 
    Log.d(TAG, "video1 surfaceDestroyed called"); 
} 

public void surfaceCreated(SurfaceHolder holder) { 
    Log.d(TAG, "Current 1 surfaceCreated called"); 
    Log.d(TAG, Boolean.valueOf(holder.isCreating()).toString()); 
    // playVideo(extras.getInt(MEDIA)); 

} 

public void PlayVideo() { 

    mVideoView.setVideoPath(path); 
    mVideoView.start(); 
    mVideoView.setMediaController(new MediaController(this)); 
    mVideoView.setVisibility(View.VISIBLE); 


} 

@Override 
public void surfaceChanged(SurfaceHolder holder, int format, int width, 
    int height) { 
    Log.d(TAG, Boolean.valueOf(holder.isCreating()).toString()); 
    // TODO Auto-generated method stub 
    Log.d(TAG, "Current video surfaceChanged called"); 

} 

} 

videoview1.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 

android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 


    <VideoView android:id="@+id/surface_view1" 
    android:layout_width="320dip" android:layout_height="240dip" 
    /> 
</LinearLayout> 
이 안드로이드 2.1 +에서 잘 작동하지만 여기에 1.6 does't은 내 코드입니다

Video2 활동 :

,771,

videoview2.xml :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

    <VideoView android:id="@+id/surface_view2" 
    android:layout_width="320dip" android:layout_height="240dip" 
    /> 

</LinearLayout> 

답변

관련 문제