コード例 #1
0
        @Override
        public void run() {
          if (nextItemIndex >= slideshow.size()) {
            // if there is music playing
            if (mediaPlayer != null && mediaPlayer.isPlaying())
              mediaPlayer.reset(); // slideshow done, reset mediaPlayer
            finish(); // return to launching Activity
          } // end if
          else {
            MediaItem item = slideshow.getMediaItemAt(nextItemIndex);

            if (item.getType() == MediaItem.MediaType.IMAGE) {
              imageView.setVisibility(View.VISIBLE); // show imageView
              videoView.setVisibility(View.INVISIBLE); // hide videoView
              new LoadImageTask().execute(Uri.parse(item.getPath()));
            } // end if
            else {
              imageView.setVisibility(View.INVISIBLE); // hide imageView
              videoView.setVisibility(View.VISIBLE); // show videoView
              playVideo(Uri.parse(item.getPath())); // plays the video
            } // end else

            ++nextItemIndex;
          } // end else
        } // end method run
コード例 #2
0
  // initializes the SlideshowPlayer Activity
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.slideshow_player);

    imageView = (ImageView) findViewById(R.id.imageView);
    videoView = (VideoView) findViewById(R.id.videoView);
    videoView.setOnCompletionListener( // set video completion handler
        new OnCompletionListener() {
          @Override
          public void onCompletion(MediaPlayer mp) {
            handler.post(updateSlideshow); // update the slideshow
          } // end method onCompletion
        } // end anonymous inner class
        ); // end OnCompletionListener

    if (savedInstanceState == null) // Activity starting
    {
      // get slideshow name from Intent's extras
      slideshowName = getIntent().getStringExtra(Slideshow.NAME_EXTRA);
      mediaTime = 0; // position in media clip
      nextItemIndex = 0; // start from first image
    } // end if
    else // Activity resuming
    {
      // get the play position that was saved when config changed
      mediaTime = savedInstanceState.getInt(MEDIA_TIME);

      // get index of image that was displayed when config changed
      nextItemIndex = savedInstanceState.getInt(IMAGE_INDEX);

      // get name of slideshow that was playing when config changed
      slideshowName = savedInstanceState.getString(SLIDESHOW_NAME);
    } // end else

    // get SlideshowInfo for slideshow to play
    slideshow = Slideshow.getSlideshowInfo(slideshowName);

    // configure BitmapFactory.Options for loading images
    options = new BitmapFactory.Options();
    options.inSampleSize = 4; // sample at 1/4 original width/height

    // if there is music to play
    if (slideshow.getMusicPath() != null) {
      // try to create a MediaPlayer to play the music
      try {
        mediaPlayer = new MediaPlayer();
        mediaPlayer.setDataSource(this, Uri.parse(slideshow.getMusicPath()));
        mediaPlayer.prepare(); // prepare the MediaPlayer to play
        mediaPlayer.setLooping(true); // loop the music
        mediaPlayer.seekTo(mediaTime); // seek to mediaTime
      } // end try
      catch (Exception e) {
        Log.v(TAG, e.toString());
      } // end catch
    } // end if

    handler = new Handler(); // create handler to control slideshow
  } // end method onCreate
コード例 #3
0
ファイル: AnimalPlayer.java プロジェクト: rperlste/android
 @Override
 public void run() {
   if (nextItemIndex >= slideshow.size()) {
     finish();
   } else {
     String item = slideshow.getImageAt(nextItemIndex);
     new LoadImageTask().execute(item);
     ++nextItemIndex;
   }
 }