Пример #1
0
  @Override
  protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);

    if (getIntent().getExtras() != null) {
      boolean doPlayTrack = getIntent().getExtras().getBoolean("playTrack");
      mArtistName = getIntent().getExtras().getString("artist");
      ActionBar actionbar = getSupportActionBar();
      if (mArtistName != null) {
        actionbar.setTitle(mArtistName);
      } else {
        actionbar.setTitle("");
      }

      if (!mHasRestored) {
        mPosition = getIntent().getExtras().getInt("position");
        ArrayList<TrackInfo> top10tracks =
            getIntent().getExtras().getParcelableArrayList("top10tracks");

        PlayerFragment playerFragment =
            (PlayerFragment) getFragmentManager().findFragmentById(R.id.ss_player_fragment);
        playerFragment.initializeTrack(mArtistName, top10tracks, mPosition, doPlayTrack);
      }
    }
  }
Пример #2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();

    if (id == R.id.ss_external_play) {
      FragmentManager fm = getFragmentManager();
      PlayerFragment fragment = (PlayerFragment) fm.findFragmentById(R.id.ss_player_fragment);
      String url = fragment.getPreviewUrl();
      Intent externalIntent = new Intent(Intent.ACTION_VIEW);
      externalIntent.setData(Uri.parse(url));
      startActivity(externalIntent);
      finish();
    }

    return super.onOptionsItemSelected(item);
  }
  public void showDialog(int position) {

    Log.v(LOG_TAG, "showDialog");
    if (mIsLargeLayout) {
      // The device is using a large layout, so show the fragment as a dialog

      mTracksListView.setItemChecked(position, true);
      FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
      PlayerFragment newFragment = new PlayerFragment();
      newFragment.show(fragmentManager, "playerFragmentDialog");

    } else {
      // The device is smaller, so show the fragment fullscreen
      Intent playerIntent = new Intent(getActivity(), PlayerActivity.class);
      startActivity(playerIntent);
    }
  }
Пример #4
0
 @Override
 public void onReceive(Context context, Intent intent) {
   PlayerFragment playerFragment =
       (PlayerFragment) getFragmentManager().findFragmentById(R.id.ss_player_fragment);
   playerFragment.initializeMediaService();
 }
  public synchronized void playVideoModel(final DownloadEntry video) {
    try {
      if (playerFragment.isPlaying()) {
        if (video.getVideoId().equals(playerFragment.getPlayingVideo().getVideoId())) {
          logger.debug("this video is already being played, skipping play event");
          return;
        }
      }
    } catch (Exception ex) {
    }

    try {
      if (playerFragment == null) {
        return;
      }

      // set callback for player events
      if (playerFragment != null) {
        playerFragment.setCallback(this);
      }

      playerFragment.setPrevNxtListners(next, prev);

      // reload this model
      environment.getStorage().reloadDownloadEntry(video);

      logger.debug("Resumed= " + playerFragment.isResumed());
      if (!playerFragment.isResumed()) {
        // playback can work only if fragment is resume
        if (playPending != null) {
          playHandler.removeCallbacks(playPending);
        }
        playPending =
            new Runnable() {
              public void run() {
                playVideoModel(video);
              }
            };
        playHandler.postDelayed(playPending, 200);
        return;
      } else {
        if (playPending != null) {
          playHandler.removeCallbacks(playPending);
        }
      }

      TranscriptModel transcript = null;

      try {
        transcript =
            environment.getServiceManager().getTranscriptsOfVideo(video.eid, video.videoId);
      } catch (Exception e) {
        logger.error(e);
      }

      String filepath = null;
      // check if file available on local
      if (video.filepath != null && video.filepath.length() > 0) {
        if (video.isDownloaded()) {
          File f = new File(video.filepath);
          if (f.exists()) {
            // play from local
            filepath = video.filepath;
            logger.debug("Playing from local file");
          }
        }
      } else {
        DownloadEntry de =
            (DownloadEntry) environment.getDatabase().getIVideoModelByVideoUrl(video.url, null);
        if (de != null) {
          if (de.filepath != null) {
            File f = new File(de.filepath);
            if (f.exists()) {
              // play from local
              filepath = de.filepath;
              logger.debug("Playing from local file for " + "another Download Entry");
            }
          }
        }
      }

      if (filepath == null || filepath.length() <= 0) {
        // not available on local, so play online
        logger.warn("Local file path not available");
        filepath = video.getBestEncodingUrl(this);
      }

      playerFragment.play(filepath, video.lastPlayedOffset, video.getTitle(), transcript, video);
    } catch (Exception e) {
      logger.error(e);
    }
  }