/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); self = this; Intent startingIntent = getIntent(); isMaster = startingIntent.getBooleanExtra("isMaster", false); int pos = MultiScreenVideoView.POSITION_LEFT; if (!isMaster) { pos = MultiScreenVideoView.POSITION_RIGHT; } mVideo = new MultiScreenVideoView(this, pos); mVideo.setVideoPath("/sdcard/android.mp4"); LinearLayout mLinearLayout = new LinearLayout(this); if (!isMaster) { mLinearLayout.setOrientation(LinearLayout.HORIZONTAL); mLinearLayout.setGravity(Gravity.RIGHT); mLinearLayout.setPadding(0, 0, 120, 0); } mLinearLayout.addView(mVideo); setContentView(mLinearLayout); mConnection = new Connection(this, serviceReadyListener); }
public void OnIncomingConnection(String device) { connectedDevice = device; if (isMaster) { Log.e("device connected", connectedDevice); mConnection.sendMessage(connectedDevice, "START"); new Thread(new PositionSyncerThread()).start(); try { Thread.sleep(400); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } mVideo.start(); } }
public void OnMessageReceived(String device, String message) { if (message.indexOf("SYNC") == 0) { try { String[] syncMessageSplit = message.split(":"); int diff = Integer.parseInt(syncMessageSplit[1]) - mVideo.getCurrentPosition(); Log.e( "master - slave diff", Integer.parseInt(syncMessageSplit[1]) - mVideo.getCurrentPosition() + ""); if ((Math.abs(diff) > 100) && (mVideo.getCurrentPosition() - lastSynced > 1000)) { mVideo.seekTo(mVideo.getCurrentPosition() + diff + 300); lastSynced = mVideo.getCurrentPosition() + diff + 300; } } catch (IllegalStateException e) { // Do nothing; this can happen as you are quitting the app // mid video } mConnection.sendMessage(connectedDevice, "ACK"); } else if (message.indexOf("START") == 0) { Log.e("received start", "0"); mVideo.start(); } else if (message.indexOf("ACK") == 0) { canSend = true; } }