예제 #1
0
 public static void enableMulticast() {
   WifiManager wifi = (WifiManager) ofActivity.getSystemService(Context.WIFI_SERVICE);
   if (wifi != null) {
     mcLock = wifi.createMulticastLock("mylock");
     mcLock.acquire();
   }
 }
예제 #2
0
    @Override
    protected String doInBackground(String... params) {
      WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
      if (wm != null) {
        MulticastLock mcLock = wm.createMulticastLock("SAAMS6");
        mcLock.acquire();
      }

      byte[] byteMessage = new byte[MAX_UDP_DATAGRAM_LEN];
      DatagramPacket packet = new DatagramPacket(byteMessage, byteMessage.length);
      MulticastSocket socket = null;
      while (keepRunning) {
        try {
          socket = new MulticastSocket(UDP_SERVER_PORT);
          socket.receive(packet);
          String message = new String(byteMessage, 0, packet.getLength());

          if (message.equals("SAMMS6 Server")) {
            ServerIP = packet.getSocketAddress().toString();
            socket.close();
            keepRunning = false;
          }
        } catch (Throwable e) {
          e.printStackTrace();
        }
      }

      return ServerIP;
    }
예제 #3
0
 public ReceiverService getReceiveService() {
   WifiManager manager =
       (WifiManager) ReceiverService.this.getSystemService(Context.WIFI_SERVICE);
   if (lock == null) {
     lock = manager.createMulticastLock("mywifi");
   }
   return ReceiverService.this;
 }
 public synchronized void open(ARDiscoveryService broadcaster, Context c) {
   ARSALPrint.v(TAG, "Opening MdsnSd based ARDiscovery");
   this.broadcaster = broadcaster;
   this.context = c;
   // create a multicast lock
   WifiManager wifi = (WifiManager) context.getSystemService(android.content.Context.WIFI_SERVICE);
   multicastLock = wifi.createMulticastLock("ARDiscovery");
 }
예제 #5
0
 public static MulticastLock aquireMulticastLock(
     final Context pContext, final String pMulticastLockName) {
   final WifiManager wifiManager = WifiUtils.getWifiManager(pContext);
   final MulticastLock multicastLock = wifiManager.createMulticastLock(pMulticastLockName);
   multicastLock.setReferenceCounted(true);
   multicastLock.acquire();
   return multicastLock;
 }
예제 #6
0
  private void acquireMulticastLock() {
    if (null != mWifiMulticastLock && mWifiMulticastLock.isHeld()) {
      mWifiMulticastLock.release();
    }

    mWifiMulticastLock = mWifiManager.createMulticastLock(TAG);
    mWifiMulticastLock.setReferenceCounted(true);
    mWifiMulticastLock.acquire();
  }
예제 #7
0
 @Override
 public void run() {
   WifiManager wifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
   multicastLock = wifiManager.createMulticastLock("multicast.test");
   multicastLock.acquire();
   try {
     findServerIpAddress();
   } catch (IOException e) {
     e.printStackTrace();
   }
   multicastLock.release();
 }
예제 #8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    String strUrl;

    setTitle(R.string.app_name);
    super.onCreate(savedInstanceState);

    WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    multicastLock = wifi.createMulticastLock("multicastLock");
    multicastLock.setReferenceCounted(true);
    multicastLock.acquire();

    getWindow().requestFeature(Window.FEATURE_PROGRESS);
    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

    setContentView(R.layout.main);
    mthis = this;

    settings = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);

    SharedSettings.getInstance(this).loadPrefSettings();
    SharedSettings.getInstance().savePrefSettings();

    playerStatus = (RelativeLayout) findViewById(R.id.playerStatus);
    playerStatusText = (TextView) findViewById(R.id.playerStatusText);
    playerHwStatus = (TextView) findViewById(R.id.playerHwStatus);

    player = (MediaPlayer) findViewById(R.id.playerView);

    strUrl =
        settings.getString("connectionUrl", "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");

    player.getSurfaceView().setZOrderOnTop(true); // necessary
    SurfaceHolder sfhTrackHolder = player.getSurfaceView().getHolder();
    sfhTrackHolder.setFormat(PixelFormat.TRANSPARENT);

    HashSet<String> tempHistory = new HashSet<String>();
    tempHistory.add("rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov");
    tempHistory.add("http://hls.cn.ru/streaming/2x2tv/tvrec/playlist.m3u8");
    tempHistory.add("rtsp://rtmp.infomaniak.ch/livecast/latele");

    player.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction() & MotionEvent.ACTION_MASK) {
              case MotionEvent.ACTION_DOWN:
                {
                  if (player.getState() == PlayerState.Paused) player.Play();
                  else if (player.getState() == PlayerState.Started) player.Pause();
                }
            }

            return true;
          }
        });

    edtIpAddressHistory = settings.getStringSet("connectionHistory", tempHistory);

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    edtIpAddress = (AutoCompleteTextView) findViewById(R.id.edit_ipaddress);
    edtIpAddress.setText(strUrl);

    edtIpAddress.setOnEditorActionListener(
        new OnEditorActionListener() {
          @Override
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
              InputMethodManager in =
                  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              in.hideSoftInputFromWindow(
                  edtIpAddress.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
              return true;
            }
            return false;
          }
        });

    btnHistory = (Button) findViewById(R.id.button_history);

    // Array of choices
    btnHistory.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            InputMethodManager in =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            in.hideSoftInputFromWindow(
                MainActivity.edtIpAddress.getApplicationWindowToken(),
                InputMethodManager.HIDE_NOT_ALWAYS);

            if (edtIpAddressHistory.size() <= 0) return;

            String urlHistory[] = {
              "rtsp://russiatoday.fms.visionip.tv/rt/Russia_al_yaum_1000k_1/1000k_1",
              "rtsp://www.tvarm.ru:1935/live/myStream1.sdp",
              "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov",
              "rtsp://live240.impek.com/brtvhd",
              "http://tv.life.ru/lifetv/480p/index.m3u8"
            };

            MainActivity.edtIpAddressAdapter =
                new ArrayAdapter<String>(
                    MainActivity.this,
                    R.layout.history_item,
                    new ArrayList<String>(edtIpAddressHistory));
            MainActivity.edtIpAddress.setAdapter(MainActivity.edtIpAddressAdapter);
            MainActivity.edtIpAddress.showDropDown();
          }
        });

    btnShot = (Button) findViewById(R.id.button_shot);

    // Array of choices
    btnShot.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            if (player != null) {
              Log.e("SDL", "getVideoShot()");

              SharedSettings sett = SharedSettings.getInstance();
              if (sett.decoderType != 0) {
                Toast.makeText(
                        getApplicationContext(), "For Software Decoder Only!", Toast.LENGTH_SHORT)
                    .show();
                return;
              }

              // VideoShot frame = player.getVideoShot(200, 200);
              VideoShot frame = player.getVideoShot(-1, -1);
              if (frame == null) return;

              // get your custom_toast.xml ayout
              LayoutInflater inflater = getLayoutInflater();

              View layout =
                  inflater.inflate(
                      R.layout.videoshot_view,
                      (ViewGroup) findViewById(R.id.videoshot_toast_layout_id));

              ImageView image = (ImageView) layout.findViewById(R.id.videoshot_image);
              image.setImageBitmap(
                  getFrameAsBitmap(frame.getData(), frame.getWidth(), frame.getHeight()));

              // Toast...
              if (toastShot != null) toastShot.cancel();

              toastShot = new Toast(getApplicationContext());
              toastShot.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
              toastShot.setDuration(Toast.LENGTH_SHORT);
              toastShot.setView(layout);
              toastShot.show();
            }
          }
        });

    btnConnect = (Button) findViewById(R.id.button_connect);
    btnConnect.setOnClickListener(this);

    btnRecord = (Button) findViewById(R.id.button_record);
    btnRecord.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View arg0) {
            is_record = !is_record;

            if (is_record) {
              // start recording
              if (player != null) {
                int record_flags =
                    PlayerRecordFlags.forType(PlayerRecordFlags.PP_RECORD_AUTO_START)
                        | PlayerRecordFlags.forType(
                            PlayerRecordFlags.PP_RECORD_SPLIT_BY_TIME); // 1 - auto start
                int rec_split_time = 30;
                player.RecordSetup(getRecordPath(), record_flags, rec_split_time, 0, "");
                player.RecordStart();
              }
            } else {
              // stop recording
              if (player != null) {
                player.RecordStop();
              }
            }

            ImageView ivLed = (ImageView) findViewById(R.id.led);
            if (ivLed != null)
              ivLed.setImageResource((is_record ? R.drawable.led_red : R.drawable.led_green));
            btnRecord.setText(is_record ? "Stop Record" : "Start Record");
          }
        });

    RelativeLayout layout = (RelativeLayout) findViewById(R.id.main_view);
    layout.setOnTouchListener(
        new OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager inputManager =
                (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            if (getWindow() != null
                && getWindow().getCurrentFocus() != null
                && getWindow().getCurrentFocus().getWindowToken() != null)
              inputManager.hideSoftInputFromWindow(
                  getWindow().getCurrentFocus().getWindowToken(), 0);
            return true;
          }
        });

    playerStatusText.setText("DEMO VERSION");
    setShowControls();
  }
    @Override
    protected Void doInBackground(Void... params) {
      Log.d("Discovery: ", "start UDP Server");
      String data = "0::deskcon";
      try {
        // Send "Ask for Hosts" Broadcast
        serverSocketUDP = new DatagramSocket(5108);
        serverSocketUDP.setBroadcast(true);

        InetAddress local = getBroadcast();

        // has a broadcast address been found
        if (local == null) {
          Log.d("Discovery: ", "no Broadcast Address found");
          return null;
        }

        DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(), local, 5108);
        serverSocketUDP.send(packet);

      } catch (Exception e) {
        e.printStackTrace();
        Log.d("Discovery: ", "could not start");
        return null;
      }

      WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
      MulticastLock lock = wifi.createMulticastLock("net.screenfreeze.deskcon");
      lock.acquire();

      // Receive responses from desktop hosts
      while (!isStopped) {
        byte[] receiveData = new byte[128];
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);

        try {
          serverSocketUDP.receive(receivePacket);
        } catch (Exception e) {
        }

        final InetAddress address = receivePacket.getAddress();

        String msg = new String(receiveData, 0, receivePacket.getLength());

        // Check for valid msg
        boolean isvalismsg = msg.split("::").length == 3;

        // Process msg if it is not our own broadcast msg
        if (!msg.equals(data) && !isStopped && isvalismsg) {

          final DesktopHost desktop = handleReceiveUdp(msg, address);
          Log.d("udp from: ", "msg " + msg + "  " + address);

          runOnUiThread(
              new Runnable() {

                @Override
                public void run() {
                  dha.add(desktop);
                }
              });
        }
      }
      lock.release();

      return null;
    }