안녕하세요 꾸준한 노력만이 입니다...

 

지금 개발중인 어플이 Vimeo의 동영상 embed code를 사용해서 웹뷰를 통해 보여주려고 합니다.

 

소스코드에 앞서 문제점을 먼저 말씀 드리자면

 

            1>  Layout이 titlebar - ScrollView(WebView가 child로 있음) 이런 구조인데

                 앱 실행시 WebView의 위에 surfaceview로 flashplayer가 실행되는 것 같습니다.

                 그래서 화면을 스크롤 하게되면 WebView가 ScrollView안에 있음에도 titlebar를 가리는 현상이 생깁니다.

                 (flashplayer를 스크롤뷰안에서 나오도록 하고 싶습니다.)

 

            2>  두번째는 동영상이 재생된후 back버튼을 누르면 종료되지 않고 전체화면에서 원래상태로 돌아오지만

                  동영상은 계속 재생되고 있습니다

                  ( back버튼을 누르면 일시정지나 정지가 되면서 원래상태로 돌아왔으면 합니다)

 

 

사진으로 보시면

 

SAM_5127.JPG     SAM_5128.JPG   SAM_5129.JPG   SAM_5130.JPG  

           <1>                            <2>                          <3>                          <4>

 

<1>이 어플을 실행했을때입니다. 초록색이 titlebar부분이고 나머지가 ScrollView로 감싸져있습니다. 사진부분이 WebView입니다.

<2>에서 처럼 스크롤시 titlebar를 가립니다.

<3>은 실행시 보여지는 화면입니다.

<4>은 back버튼을 누른후  원래 상태로 돌아왔지만 동영상은 계속 재생중입니다.

 

mian Activity입니다.

 

 import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
public class WebViewInFlash extends Activity {
 private RelativeLayout header;
 private RelativeLayout titlebar;
 private MyWebVIew mWeb;
 private View mCustomView;
 private FrameLayout mCustomViewContainer;
 private WebChromeClient.CustomViewCallback mCustomViewCallback;
 private MyWebChromeClient mWebChromeClient;
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.freeboard_description);
  init();
  // video view remove
  if (inCustomView())
   hideCustomView();
  
  loadData();
  
  mWeb.setVisibility(View.VISIBLE);
 }
 private void init() {
  mCustomViewContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content);
  mWeb = (MyWebVIew) findViewById(R.id.freeboard_desc_webview);
  header = (RelativeLayout) findViewById(R.id.freeboard_desc_header);
 }
 
 private void loadData() {
  mWebChromeClient = new MyWebChromeClient();
  mWeb.setWebChromeClient(mWebChromeClient);
  mWeb.setWebViewClient(new MyWebClient());
  WebSettings set = mWeb.getSettings();
  set.setCacheMode(WebSettings.LOAD_NO_CACHE);
  set.setUserAgent(0);
  set.setPluginsEnabled(true);
  mWeb.loadUrl("http://player.vimeo.com/video/24243147?title=0&byline=0");
  
 }
 
 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  callHiddenWebViewMethod("onResume");
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  callHiddenWebViewMethod("onPause");
 }
 @Override
 public void onBackPressed() {
  // TODO Auto-generated method stub
  super.onBackPressed();
  if (inCustomView()) {
   hideCustomView();
  }
  finish();
 }
 private void callHiddenWebViewMethod(String name) {
  if (mWeb != null) {
   try {
    Method method = WebView.class.getMethod(name);
    method.invoke(mWeb);
   } catch (SecurityException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IllegalArgumentException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (NoSuchMethodException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IllegalAccessException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (InvocationTargetException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
  }
 }
 public boolean inCustomView() {
  return (mCustomView != null);
 }
 public void hideCustomView() {
  mWebChromeClient.onHideCustomView();
 }
 private class MyWebChromeClient extends WebChromeClient {
  private Bitmap mDefaultVideoPoster;
  private View mVideoProgressView;
  @Override
  public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
   if (mCustomView != null) {
    callback.onCustomViewHidden();
    return;
   }
   header.setVisibility(View.GONE);
   titlebar.setVisibility(View.GONE);
   mCustomViewContainer.addView(view); // attach mediaplayer
   mCustomView = view;
   mCustomViewCallback = callback;
   mCustomViewContainer.setVisibility(View.VISIBLE);
  }
  @Override
  public void onHideCustomView() {
   if (mCustomView == null)
    return;
   mCustomView.setVisibility(View.GONE);
   mCustomViewContainer.removeView(mCustomView);
   mCustomView = null;
   mCustomViewContainer.setVisibility(View.GONE);
   mCustomViewCallback.onCustomViewHidden();
   header.setVisibility(View.VISIBLE);
   titlebar.setVisibility(View.VISIBLE);
  }
  public Bitmap getDefaultVideoPoster() {
   if (mDefaultVideoPoster == null) {
    mDefaultVideoPoster = BitmapFactory.decodeResource(getResources(), R.drawable.background);
   }
   return mDefaultVideoPoster;
  }
  @Override
  public View getVideoLoadingProgressView() {
   // if (mVideoProgressView == null) {
   // LayoutInflater inflater =
   // LayoutInflater.from(getApplicationContext());
   // mVideoProgressView =
   // inflater.inflate(R.layout.video_loading_progress, null);
   // }
   return mVideoProgressView;
  }
  @Override
  public void onReceivedTitle(WebView view, String title) {
   // ((Activity) getApplicationContext()).setTitle(title);
  }
  @Override
  public void onProgressChanged(WebView view, int newProgress) {
   // getWindow().setFeatureInt(Window.FEATURE_PROGRESS, newProgress *
   // 100);
  }
 }
}

 

xml 입니다.

 

 <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="#ffffff">

 <!-- Title bar -->
 <RelativeLayout
  android:id="@+id/freeboard_desc_Titlebar"
  android:layout_width="fill_parent"
  android:layout_height="50dp"
  android:layout_alignParentTop="true"
  android:background="#7AAF73">

  <TextView
   android:id="@+id/freeboard_desc_Titlebar_text"
   android:layout_centerInParent="true"
   android:gravity="center"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:text="웹뷰 테스트"
   style="@style/titlestyle" />

 </RelativeLayout>


 <!-- Contents Layout -->
 <RelativeLayout
  android:id="@+id/freeboard_desc_header"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#ffffff"
  android:layout_below="@+id/freeboard_desc_Titlebar">

  <ScrollView
   android:id="@+id/freeboard_desc_scrollview"
   android:layout_alignParentTop="true"
   android:layout_above="@+id/freeboard_desc_toolbar"
   android:layout_height="match_parent"
   android:layout_width="match_parent">
   <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <TextView
     android:id="@+id/freeboard_desc_title"
     android:layout_width="fill_parent"
     android:layout_marginTop="15dp"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:layout_marginBottom="3dp"
     android:gravity="left"
     android:text="웹뷰 테스트입니다."
     style="@style/desctitlestyle"
     android:layout_height="wrap_content" />


    <ImageView
     android:id="@+id/freeboard_desc_dividor"
     android:layout_height="1dp"
     android:layout_width="fill_parent"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:background="#7AAF73"></ImageView>

    <com.test.main.MyWebVIew
     android:id="@+id/freeboard_desc_webview"
     android:layout_height="200dp"
     android:layout_width="fill_parent"
     android:layout_gravity="center_horizontal"
     android:layout_marginTop="10dp"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp" />

    <TextView
     android:id="@+id/freeboard_desc_description"
     android:layout_marginTop="10dp"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:layout_width="fill_parent"
     android:text="웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다. 웹뷰 테스트입니다."
     style="@style/desctextstyle"
     android:lineSpacingExtra="25dp"
     android:layout_height="wrap_content" />
    <ImageView
     android:layout_height="1dp"
     android:layout_width="fill_parent"
     android:layout_marginTop="10dp"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:background="#7AAF73"></ImageView>

    <TextView
     android:id="@+id/freeboard_desc_time"
     android:gravity="right"
     android:layout_width="fill_parent"
     android:layout_marginTop="10dp"
     android:layout_marginLeft="20dp"
     android:layout_marginRight="20dp"
     android:layout_marginBottom="20dp"
     android:padding="0dp"
     style="@style/desctimestyle"
     android:layout_height="20dp" />
   </LinearLayout>
  </ScrollView>
  <FrameLayout
   android:id="@+id/fullscreen_custom_content"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="#000000"
   android:visibility="gone">
  </FrameLayout>

 </RelativeLayout>
</RelativeLayout>

 

 

 


AndroidManifest.xml입니다

 

 <?xml version="1.0" encoding="utf-8"?>
<manifest
 xmlns:android="http://schemas.android.com/apk/res/android"
 package="net.tcnmedia.main"
 android:versionCode="1"
 android:versionName="1.0">
 <uses-sdk
  android:minSdkVersion="8" />

 <application
  android:icon="@drawable/icon"
  android:label="@string/app_name">
  <activity
   android:name=".WebViewInFlash"
   android:label="@string/app_name"
   android:theme="@android:style/Theme.NoTitleBar"
   android:configChanges="orientation|keyboardHidden">
   <intent-filter>
    <action
     android:name="android.intent.action.MAIN" />
    <category
     android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
  </activity>

 </application>

 <uses-permission
  android:name="android.permission.INTERNET" />
 <uses-permission
  android:name="android.permission.ACCESS_NETWORK_STATE" />
 <uses-permission
  android:name="android.permission.WAKE_LOCK" />
</manifest>


살펴봐 주시고 많은 답변 부탁드려요. 읽어 주셔서 감사합니다.