Ignore:
Timestamp:
Mar 18, 2015 12:02:51 PM (9 years ago)
Author:
ming
Message:

Re #1823 (pjsua2 video api): sample usage of Video Window API in pjsua2 app for android

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/swig/java/android/src/org/pjsip/pjsua2/app/CallActivity.java

    r4840 r4997  
    2222import android.os.Handler; 
    2323import android.os.Message; 
     24import android.view.SurfaceHolder; 
     25import android.view.SurfaceView; 
    2426import android.view.View; 
    2527import android.widget.Button; 
     
    2931import org.pjsip.pjsua2.*; 
    3032 
    31 public class CallActivity extends Activity implements Handler.Callback { 
     33public class CallActivity extends Activity 
     34        implements Handler.Callback, SurfaceHolder.Callback 
     35{ 
    3236         
    3337        public static Handler handler_; 
     
    4044                super.onCreate(savedInstanceState); 
    4145                setContentView(R.layout.activity_call); 
     46                 
     47                SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 
     48                if (MainActivity.currentCall == null || 
     49                        MainActivity.currentCall.vidWin == null) 
     50                { 
     51                        surfaceView.setVisibility(View.GONE); 
     52                } 
     53                surfaceView.getHolder().addCallback(this); 
    4254                 
    4355                handler_ = handler; 
     
    5971        handler_ = null; 
    6072    } 
    61          
     73 
     74    private void updateVideoWindow(SurfaceHolder holder) { 
     75                if (MainActivity.currentCall != null && 
     76                        MainActivity.currentCall.vidWin != null) 
     77                { 
     78                        VideoWindowHandle vidWH = new VideoWindowHandle(); 
     79                        if (holder == null) 
     80                                vidWH.getHandle().setWindow(null); 
     81                        else 
     82                                vidWH.getHandle().setWindow(pjsua2.android_opengl_get_surface(holder.getSurface())); 
     83                        try { 
     84                                MainActivity.currentCall.vidWin.setWindow(vidWH); 
     85                        } catch (Exception e) {} 
     86                } 
     87    } 
     88     
     89        public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 
     90                updateVideoWindow(holder); 
     91    } 
     92 
     93    public void surfaceCreated(SurfaceHolder holder) { 
     94    } 
     95 
     96    public void surfaceDestroyed(SurfaceHolder holder) { 
     97        updateVideoWindow(null); 
     98    } 
     99     
    62100        public void acceptCall(View view) { 
    63101                CallOpParam prm = new CallOpParam(); 
     
    87125        } 
    88126         
     127        private void setupVideoSurface() { 
     128 
     129                SurfaceView surfaceView = (SurfaceView)findViewById(R.id.surfaceIncomingVideo); 
     130                surfaceView.setVisibility(View.VISIBLE); 
     131                updateVideoWindow(surfaceView.getHolder()); 
     132                 
     133        } 
     134         
    89135        @Override 
    90136        public boolean handleMessage(Message m) { 
     
    95141                        updateCallState(lastCallInfo); 
    96142                         
     143                } else if (m.what == MainActivity.MSG_TYPE.CALL_MEDIA_STATE) { 
     144                         
     145                        if (MainActivity.currentCall.vidWin != null) { 
     146                                /* If there's incoming video, display it. */ 
     147                                setupVideoSurface(); 
     148                        } 
     149 
    97150                } else { 
    98151                         
Note: See TracChangeset for help on using the changeset viewer.