Пример #1
0
  private void evaluatePredict(int mask) {
    Leg.i(TAG, "evaluatePredict(" + mask + ")");
    calculatePredict(mask);

    Leg.i(TAG, "calculated predict: " + mPredict);
    if ((mPredict & START_PRD_SB_SV) == START_PRD_SB_SV) {
      Leg.i(TAG, "prediction: foreground surface");
      Surface surface = mSurfaceHolder.getSurface();
      if (surface != null && surface.isValid()) {
        mPlaybackService.setForegroundSurfaceHolder(mSurfaceHolder);
      } else {
        mPlaybackService.setForegroundSurfaceHolder(null);
      }
    }

    if ((mPredict & START_PRD_SI_SB_SV) == START_PRD_SI_SB_SV) {
      Leg.i(TAG, "prediction: send start playback message");
      mHandler.removeMessages(START_PLAY_BACK);
      mHandler.removeMessages(STOP_PLAY_BACK);
      if (!mPlaybackService.isPlaying()) {
        mHandler.obtainMessage(STOP_PLAY_BACK).sendToTarget();
        mHandler.obtainMessage(START_PLAY_BACK).sendToTarget();
      }
    }
  }
Пример #2
0
  void startPlaybackInService(boolean fg, boolean freshStart) {
    Leg.i(
        TAG,
        "startPlaybackInService =====================  mUris : "
            + mUris.size()
            + ", muris :"
            + mUris.toString());

    Intent localIntent = mStartIntent;
    localIntent.setClass(this, PlaybackService.class);
    localIntent.putExtra("com.example.tinyplayer.Binding", false);
    localIntent.putExtra("com.example.tinyplayer.CurrentPosition", 0);
    localIntent.putExtra("com.example.tinyplayer.StartAtOnce", true);
    localIntent.putParcelableArrayListExtra("com.example.tinyplayer.Uris", mUris);

    localIntent.putExtra("com.example.tinyplayer.Foreground", fg);
    localIntent.putExtra("com.example.tinyplayer.FreshStart", freshStart);
    localIntent.putExtra("com.example.tinyplayer.PresentationDisplayId", mPresentationId);

    if (mPlaybackService == null) {
      if (fg || freshStart) {
        Leg.i(TAG, "start new service");
        startService(localIntent);
      }

    } else {
      Leg.i(TAG, "use existing service");
      mPlaybackService.continueInBackground(localIntent);
    }
  }
Пример #3
0
  @Override
  public void onClick(View v) {
    if (mPlaybackService == null) return;
    if (v == mVideoSurface || v == playButton) {
      if (mPlaybackService != null) {
        MyMediaPlayer.PLAYBACK_STATE state = mPlaybackService.getPlaybackState();
        switch (state) {
          case PAUSED:
            mPlaybackService.resumePlayback();
            mediaControllerLayout.setVisibility(View.VISIBLE);
            playButton.setImageResource(R.drawable.ic_media_pause);
            //                    mPauseImage.setImageResource(R.drawable.ic_media_pause);
            break;
          case PLAYING:
            mPlaybackService.pausePlayback();
            mediaControllerLayout.setVisibility(View.VISIBLE);
            playButton.setImageResource(R.drawable.ic_media_play);
            //                    mPauseImage.setImageResource(R.drawable.ic_media_play);
            break;
          default:
            pickVideo();
            break;
        }
      }
    } else if (v == mNextButton_slider) {

      mPlaybackService.setNextPic();

      Leg.i(TAG, "mNextButton_slider ====================== ");

    } else if (v == mPreviousButton_slider) {
      Leg.i(TAG, "mPreviousButton_slider ====================== ");
      mPlaybackService.setPreviousPic();

    } else if (v == mPlay_pauseButton_slider) {
      mPlaybackService.setpausePlayback();

    } else if (v == slidingMenu_open || v == slidingMenu_open_image || v == slidingMenu_open_text) {
      pickVideo();
      showContent();

    } else if (v == slidingMenu_repeat
        || v == slidingMenu_repeat_image
        || v == slidingMenu_repeat_text) {
      switchLooping();
    } else if (v == slidingMenu_about
        || v == slidingMenu_about_image
        || v == slidingMenu_about_text) {
      openAboutDialog();

    } else if (v == sliding_floatwindow || v == sliding_floatwindow_text) {
      if (sliding_checkbox_floatwindow.isChecked()) {
        sliding_checkbox_floatwindow.setChecked(false);
      } else {
        sliding_checkbox_floatwindow.setChecked(true);
      }
    }
  }
Пример #4
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Leg.i(
        TAG,
        String.format(
            "================================requestCode:%d, resultCode:%d",
            requestCode, resultCode));
    if (requestCode == PICK_VIDEO_REQUEST_CODE) {
      if (resultCode == RESULT_OK) {

        mUris.clear();
        Uri uri = data.getData();

        if (uri != null) {
          Intent newIntent = new Intent(mStartIntent);
          newIntent.setAction("INNER_ACTION_VIDEO_PICKED");
          newIntent.setData(uri);
          setIntent(newIntent);
        }

      } else {
        // don't set new video path
      }
    }
    super.onActivityResult(requestCode, resultCode, data);
  }
Пример #5
0
 @Override
 protected void onStart() {
   Leg.i(TAG, "onStart()=============================================");
   mPredict = 0;
   handleStartIntent();
   super.onStart();
 }
Пример #6
0
 private void fetchUris(int i, boolean mutiple, Intent intent) {
   mUris.clear();
   if (mutiple) {
     ArrayList<Uri> tempUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
     mUris.addAll(tempUris);
   } else {
     Uri tempUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
     mUris.add(tempUri);
   }
   int size = mUris.size();
   Leg.i(TAG, "size of mUris in fetchUris()" + size);
   if (size <= 0) {
     return;
   }
 }
Пример #7
0
  @Override
  protected void onPause() {
    Leg.i(
        TAG,
        "onPause()==============================================================================");

    MyMediaPlayer.PLAYBACK_STATE state = mPlaybackService.getPlaybackState();
    Leg.i(TAG, "current play state is: " + state);
    switch (state) {
      case PAUSED:
        break;
      case PLAYING:
        Leg.i(TAG, "going to start background pb");
        startPlaybackInService(false, false);
        break;
      default:
        break;
    }

    mMediaRouter.removeCallback(mMediaRouterCallback);
    PlaybackService.STOP_SERVICE_ON_COMPLETE = true;
    doUnbindPlaybackService();
    super.onPause();
  }
Пример #8
0
 void doBindPlaybackService() {
   if (mIsBoundToPlaybackService && mPlaybackService != null) {
     return;
   }
   Intent localIntent = getIntent();
   localIntent.setClass(this, PlaybackService.class);
   localIntent.putExtra("com.example.tinyplayer.Binding", true);
   localIntent.putExtra("com.example.tinyplayer.CurrentPosition", 0);
   localIntent.putExtra("com.example.tinyplayer.StartAtOnce", false);
   ComponentName name = startService(localIntent);
   Leg.i(TAG, "going to bound service ,++++++++++++++++++++++++++++++++++ name : " + name);
   if (name != null) {
     bindService(
         new Intent(Player.this, PlaybackService.class), mConnection, Context.BIND_AUTO_CREATE);
   }
 }
Пример #9
0
  @Override
  protected void onResume() {
    if (presentationRouteSelected()) {
      mBackgroundImage.setImageResource(R.drawable.miracast);
      /*
       * if(MySlideShowPlayer.isImage){ showSlidingController(); }
       */
    } else {
      mBackgroundImage.setImageResource(R.drawable.background);
    }

    if (MySlideShowPlayer.isImage) {
      showSlidingController();
    }

    Leg.i(TAG, "onResume()============================================================");
    doBindPlaybackService();
    mMediaRouter.addCallback(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouterCallback);
    mSurfaceHolder.addCallback(mFgSurfaceHolderCB);
    PlaybackService.STOP_SERVICE_ON_COMPLETE = false;
    super.onResume();
  }
Пример #10
0
 private void calculatePredict(int mask) {
   Leg.i(TAG, "calculatePredict(): " + mask);
   mPredict |= mask;
 }
Пример #11
0
  private void handleStartIntent() {
    Leg.i(TAG, "handleStartIntent");
    mStartIntent = getIntent();

    if (mStartIntent == null) {
      return;
    }

    String action = mStartIntent.getAction();
    String type = mStartIntent.getType();
    Leg.i(TAG, "action: " + action + ", type: " + type);

    if ("INNER_ACTION_PROCESSED".equals(action)) {
      return;
    }

    boolean sliding = mStartIntent.getBooleanExtra("com.example.tinyplayer.sliding", false);

    if (sliding) {
      // dismissSlidingController();
    }

    Intent newIntent = new Intent(mStartIntent);
    newIntent.setAction("INNER_ACTION_PROCESSED");
    setIntent(newIntent);
    // android.intent.action.MAIN

    mUris.clear();

    if (Intent.ACTION_SEND.equals(action) && type != null) {
      Leg.i(TAG, "ACTION_SEND: " + type.toString());
      if (type.startsWith("image/")) {
        fetchUris(2, false, mStartIntent);

      } else if (type.startsWith("video/")) {
        fetchUris(1, false, mStartIntent);
      }
    } else if (Intent.ACTION_SEND_MULTIPLE.equals(action) && type != null) {
      Leg.i(TAG, "ACTION_SEND_MULTIPLE: " + type.toString());
      if (type.startsWith("image/")) {
        fetchUris(2, true, mStartIntent);
        showSlidingController();
      } else if (type.startsWith("video/")) {
        fetchUris(1, true, mStartIntent);

      } else if (type.startsWith("*/")) {
        fetchUris(0, true, mStartIntent);
      }
    } else if ("INNER_ACTION_VIDEO_PICKED".equals(action)) {
      mUris.clear();
      Uri temp = mStartIntent.getData();
      if (temp != null) {
        mUris.add(temp);
      }
    }

    int size = mUris.size();
    Leg.i(TAG, "size of mUris: " + size);

    if (size >= 1) {
      evaluatePredict(START_PRD_START_INTENT);
    }
  }
Пример #12
0
 @Override
 protected void onNewIntent(Intent intent) {
   Leg.i(TAG, "onNewIntent()");
   setIntent(intent);
   super.onNewIntent(intent);
 }
Пример #13
0
 @Override
 protected void onDestroy() {
   Leg.i(TAG, "onDestory()=============================================");
   super.onDestroy();
 }
Пример #14
0
 @Override
 protected void onStop() {
   Leg.i(TAG, "onStop()=================================================");
   super.onStop();
 }
Пример #15
0
 @Override
 protected void onRestart() {
   Leg.i(TAG, "onRestart()");
   super.onRestart();
 }
Пример #16
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Leg.i(TAG, "onCreate()================================");
    super.onCreate(savedInstanceState);

    if (!isPortrait()) {
      // requestWindowFeature(Window.FEATURE_NO_TITLE);
      updateFullscreenStatus(true);
    }
    setContentView(R.layout.activity_player);

    mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);

    mContentView = getWindow().getDecorView().findViewById(android.R.id.content);
    mBackgroundImage = (ImageView) findViewById(R.id.background);

    //        mPauseImage = (ImageView) findViewById(R.id.play_pause);
    mVideoSurface = (SurfaceView) findViewById(R.id.video_surface);

    mPreviousButton_slider = (ImageButton) findViewById(R.id.prev);
    mPlay_pauseButton_slider = (ImageButton) findViewById(R.id.pause);
    mNextButton_slider = (ImageButton) findViewById(R.id.next);

    mVideoSurface.setZOrderOnTop(true);
    mVideoSurface.setAlpha((float) 0.18);
    mVideoSurface.getHolder().setFormat(PixelFormat.TRANSLUCENT);

    //        mPauseImage.setOnClickListener(this);
    mVideoSurface.setOnClickListener(this);
    mVideoSurface.setOnTouchListener(this);

    mPreviousButton_slider.setOnClickListener(this);
    mPlay_pauseButton_slider.setOnClickListener(this);
    mNextButton_slider.setOnClickListener(this);

    //
    mPredict = 0;
    getSurfaceHolder();

    //
    mDefaultDM = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(mDefaultDM);

    this.registerReceiver(
        new BroadcastReceiver() {

          @Override
          public void onReceive(Context context, Intent intent) {
            // TODO Auto-generated method stub
            dismissSlidingController();
          }
        },
        mIntentfl);

    mediaControllerLayout = findViewById(R.id.mediaControllerLayout);
    mSeekBar = (SeekBar) findViewById(R.id.videoSeekBar);

    mSeekBar.setOnSeekBarChangeListener(
        new OnSeekBarChangeListener() {
          @Override
          public void onStopTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onStartTrackingTouch(SeekBar seekBar) {}

          @Override
          public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
              mPlaybackService.seekTo(
                  (int) (progress * 1.0 / seekBar.getMax() * (mPlaybackService.getDuration())));
              seekBar.setProgress(progress);
            }
          }
        });

    scheduledExecutorService = Executors.newScheduledThreadPool(1);
    handler = new Handler();

    scheduledExecutorService.scheduleAtFixedRate(
        new Runnable() {

          @Override
          public void run() {
            handler.post(
                new Runnable() {
                  @Override
                  public void run() {
                    Log.d(TAG, "test-----");
                    if (mPlaybackService.isPlaying()) {
                      Log.d(TAG, "test++++");
                      int position = mPlaybackService.getCurrentPosition();
                      int duration = mPlaybackService.getDuration();
                      Log.d(
                          TAG,
                          "test++++" + Integer.toString(duration) + Integer.toString(position));
                      mSeekBar.setProgress(
                          (int) ((float) position / (float) duration * mSeekBar.getMax()));

                      mediaControllerLayout.setVisibility(View.VISIBLE);
                      playButton.setImageResource(R.drawable.ic_media_pause);

                      Log.d(TAG, "test++++" + (int) (position / duration * mSeekBar.getMax()));
                    }
                  }
                });
          }
        },
        1000,
        1000,
        TimeUnit.MILLISECONDS);

    playButton = (ImageButton) findViewById(R.id.playButton);
    playButton.setOnClickListener(this);

    // icon show sliding menu
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // sliding menu
    setBehindContentView(R.layout.slidingmenu_left);

    // customize the SlidingMenu
    SlidingMenu sm = getSlidingMenu();
    sm.setMode(SlidingMenu.LEFT);
    sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
    sm.setFadeDegree(0.0f);
    sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
    sm.setBehindScrollScale(0.0f);
    // animation
    sm.setBehindCanvasTransformer(
        new CanvasTransformer() {
          @Override
          public void transformCanvas(Canvas canvas, float percentOpen) {
            // TODO Auto-generated method stub
            Log.d(TAG, "testAni---------------");
            canvas.translate(0, 0);
          }
        });

    slidingMenu_open = (LinearLayout) findViewById(R.id.sliding_open);
    slidingMenu_open_image = (ImageView) findViewById(R.id.sliding_open_image);
    slidingMenu_open_text = (TextView) findViewById(R.id.sliding_open_text);

    slidingMenu_repeat = (LinearLayout) findViewById(R.id.sliding_loop);
    slidingMenu_repeat_image = (ImageView) findViewById(R.id.sliding_loop_image);
    slidingMenu_repeat_text = (TextView) findViewById(R.id.sliding_loop_text);

    slidingMenu_about = (LinearLayout) findViewById(R.id.sliding_about);
    slidingMenu_about_image = (ImageView) findViewById(R.id.sliding_about_image);
    slidingMenu_about_text = (TextView) findViewById(R.id.sliding_about_text);

    sliding_floatwindow = (LinearLayout) findViewById(R.id.sliding_floatwindow);
    sliding_checkbox_floatwindow = (CheckBox) findViewById(R.id.sliding_checkbox_floatwindow);
    sliding_floatwindow_text = (TextView) findViewById(R.id.sliding_floatwindow_text);

    slidingMenu_open.setOnClickListener(this);
    slidingMenu_open.setOnClickListener(this);
    slidingMenu_open_text.setOnClickListener(this);

    slidingMenu_repeat.setOnClickListener(this);
    slidingMenu_repeat_image.setOnClickListener(this);
    slidingMenu_repeat_text.setOnClickListener(this);

    slidingMenu_about.setOnClickListener(this);
    slidingMenu_about_image.setOnClickListener(this);
    slidingMenu_about_text.setOnClickListener(this);

    sliding_floatwindow.setOnClickListener(this);
    sliding_floatwindow_text.setOnClickListener(this);

    sliding_checkbox_floatwindow.setOnCheckedChangeListener(
        new OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            boolean float_window_value = sliding_checkbox_floatwindow.isChecked();
            editor.putBoolean("sliding_checkbox_floatwindow", float_window_value);
            editor.commit();
            Log.d(
                TAG,
                "<><><><><><><> if float windows set to: " + Boolean.toString(float_window_value));
          }
        });

    settings = getSharedPreferences("floatWindow", 0);
    editor = settings.edit();

    boolean ifPlayInFloatWindow = settings.getBoolean("sliding_checkbox_floatwindow", false);
    Log.d(TAG, "<><><><><><><> play in float window: " + Boolean.toString(ifPlayInFloatWindow));
    sliding_checkbox_floatwindow.setChecked(ifPlayInFloatWindow);
  }