コード例 #1
0
 private void destroyLocalPlayer() {
   if (mLocalPlayer != null) {
     mLocalPlayer.reset();
     mLocalPlayer.release();
     mLocalPlayer = null;
   }
 }
コード例 #2
0
  @GuiCallback("pop")
  public void onPopDown(Widget w, MouseDownEvent event) {
    if (player.isPlaying()) {
      if (player.isPaused()) player.resume();
      else player.pause();
    } else {
      player.startPlay();
    }

    updatePopState();
    gui.postEvent(new UpdateMediaEvent());
  }
コード例 #3
0
 /** Stops a playing ringtone. */
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:28:26.979 -0500",
     hash_original_method = "25B57E3869C6FCC0565FBD24EEAB9FA0",
     hash_generated_method = "D54276E98CE38A3B15A1D16585CD8968")
 public void stop() {
   if (mAudio != null) {
     mAudio.reset();
     mAudio.release();
     mAudio = null;
   }
 }
コード例 #4
0
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:28:26.967 -0500",
     hash_original_method = "3D9FD67EE5212878A40EB00FDD255FB4",
     hash_generated_method = "64022A1AA54923F2F5BCB6D43B903CE2")
 private void openMediaPlayer() throws IOException {
   if (mAudio != null) {
     mAudio.release();
   }
   mAudio = new MediaPlayer();
   if (mUri != null) {
     mAudio.setDataSource(mContext, mUri);
   } else if (mFileDescriptor != null) {
     mAudio.setDataSource(mFileDescriptor);
   } else if (mAssetFileDescriptor != null) {
     // Note: using getDeclaredLength so that our behavior is the same
     // as previous versions when the content provider is returning
     // a full file.
     if (mAssetFileDescriptor.getDeclaredLength() < 0) {
       mAudio.setDataSource(mAssetFileDescriptor.getFileDescriptor());
     } else {
       mAudio.setDataSource(
           mAssetFileDescriptor.getFileDescriptor(),
           mAssetFileDescriptor.getStartOffset(),
           mAssetFileDescriptor.getDeclaredLength());
     }
   } else {
     throw new IOException("No data source set.");
   }
   mAudio.setAudioStreamType(mStreamType);
   mAudio.prepare();
 }
コード例 #5
0
 /**
  * Whether this ringtone is currently playing.
  *
  * @return True if playing, false otherwise.
  */
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:28:26.981 -0500",
     hash_original_method = "0CA36CF7485684069EDD095AE8455157",
     hash_generated_method = "113EE03FEC2AB5B9B31E6309FF6709D4")
 public boolean isPlaying() {
   return mAudio != null && mAudio.isPlaying();
 }
コード例 #6
0
 /** @hide */
 public void setVolume(float volume) {
   if (mLocalPlayer != null) {
     mLocalPlayer.setVolume(volume);
   } else if (mAllowRemote && mRemotePlayer != null) {
     try {
       mRemotePlayer.setVolume(mRemoteToken, volume);
     } catch (RemoteException e) {
       Log.w(TAG, "Problem setting ringtone volume: " + e);
     }
   }
 }
コード例 #7
0
  /**
   * Set {@link Uri} to be used for ringtone playback. Attempts to open locally, otherwise will
   * delegate playback to remote {@link IRingtonePlayer}.
   *
   * @hide
   */
  public void setUri(Uri uri) {
    destroyLocalPlayer();

    mUri = uri;
    if (mUri == null) {
      return;
    }

    // TODO: detect READ_EXTERNAL and specific content provider case, instead of relying on throwing

    if (isSoundCustomized()) {
      // instead of restore to default ringtone.
      restoreRingtoneIfNotExist(Settings.System.RINGTONE);
      restoreRingtoneIfNotExist(Settings.System.RINGTONE_2);
    }

    // try opening uri locally before delegating to remote player
    mLocalPlayer = new MediaPlayer();
    try {
      mLocalPlayer.setDataSource(mContext, mUri);
      mLocalPlayer.setAudioAttributes(mAudioAttributes);
      mLocalPlayer.prepare();

    } catch (SecurityException | IOException e) {
      destroyLocalPlayer();
      if (!mAllowRemote) {
        Log.w(TAG, "Remote playback not allowed: " + e);
      }
    }

    if (LOGD) {
      if (mLocalPlayer != null) {
        Log.d(TAG, "Successfully created local player");
      } else {
        Log.d(TAG, "Problem opening; delegating to remote player");
      }
    }
  }
コード例 #8
0
 private boolean playFallbackRingtone() {
   if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) {
     int subId = RingtoneManager.getDefaultRingtoneSubIdByUri(mUri);
     if (subId != -1 && RingtoneManager.getActualRingtoneUriBySubId(mContext, subId) != null) {
       // Default ringtone, try fallback ringtone.
       try {
         AssetFileDescriptor afd =
             mContext.getResources().openRawResourceFd(com.android.internal.R.raw.fallbackring);
         if (afd != null) {
           mLocalPlayer = new MediaPlayer();
           if (afd.getDeclaredLength() < 0) {
             mLocalPlayer.setDataSource(afd.getFileDescriptor());
           } else {
             mLocalPlayer.setDataSource(
                 afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
           }
           mLocalPlayer.setAudioAttributes(mAudioAttributes);
           mLocalPlayer.prepare();
           mLocalPlayer.start();
           afd.close();
           return true;
         } else {
           Log.e(TAG, "Could not load fallback ringtone");
         }
       } catch (IOException ioe) {
         destroyLocalPlayer();
         Log.e(TAG, "Failed to open fallback ringtone");
       } catch (NotFoundException nfe) {
         Log.e(TAG, "Fallback ringtone does not exist");
       }
     } else {
       Log.w(TAG, "not playing fallback for " + mUri);
     }
   }
   return false;
 }
コード例 #9
0
 @Test
 public void play() {
   player.play();
   /*
    * Here it¡¯s asserting that the message from the SgtPeppers.play() method
    * was sent to the console.
    */
   assertEquals(
       "Playing Sgt. Pepper's Lonely Hearts Club Band by The Beatles\r\n", // StandardOutputStreamLog window \r\n  //linux \n
       log.getLog());
   /*
    * If you verify logs that contain line separators than the separators
    * are different (e.g. Linux: \n , Windows: \r\n ).
    */
 }
コード例 #10
0
 /**
  * Whether this ringtone is currently playing.
  *
  * @return True if playing, false otherwise.
  */
 public boolean isPlaying() {
   if (mLocalPlayer != null) {
     return mLocalPlayer.isPlaying();
   } else if (mAllowRemote && (mRemotePlayer != null)) {
     try {
       return mRemotePlayer.isPlaying(mRemoteToken);
     } catch (RemoteException e) {
       Log.w(TAG, "Problem checking ringtone: " + e);
       return false;
     }
   } else {
     Log.w(TAG, "Neither local nor remote playback available");
     return false;
   }
 }
コード例 #11
0
  @PostConstruct
  private void initialize() {
    _mediaPlayer.addMediaPlayerListener(
        new AbstractMediaPlayerListener() {
          @Override
          public void paused(final QueueTrack currentTrack) {
            _trackPlayTime =
                _trackPlayTime + ((System.currentTimeMillis() - _trackTimePointer) / 1000);
          }

          @Override
          public void stopped(final QueueTrack currentTrack) {
            _trackPlayTime =
                _trackPlayTime + ((System.currentTimeMillis() - _trackTimePointer) / 1000);
          }

          @Override
          public void resume(final QueueTrack currentTrack) {
            _trackTimePointer = System.currentTimeMillis();
          }

          @Override
          public void trackStart(final QueueTrack queueTrack) {
            _trackStartTime = System.currentTimeMillis();
            _trackTimePointer = _trackStartTime;
            _trackPlayTime = 0;
          }

          @Override
          public void trackEnd(final QueueTrack queueTrack, final boolean forcedEnd) {
            _trackPlayTime =
                _trackPlayTime + ((System.currentTimeMillis() - _trackTimePointer) / 1000);
            _historicalStorage.addHistory(
                new TrackHistory(
                    queueTrack.getQueue(),
                    queueTrack.getTrackUri(),
                    queueTrack.getSource(),
                    queueTrack.getQueueEntry().getId(),
                    !forcedEnd,
                    (int) _trackPlayTime,
                    _trackStartTime));
            _trackPlayTime = 0;
            _trackTimePointer = 0;
          }
        });
  }
コード例 #12
0
  private Widget createMedia(Media media) {
    Widget ret = loaded.getWidget("t_one").copy();
    DrawTexture.get(ret.getWidget("icon")).texture = media.cover;
    TextBox.get(ret.getWidget("title")).content = media.getDisplayName();
    TextBox.get(ret.getWidget("desc")).content = media.getDesc();
    TextBox.get(ret.getWidget("time")).content = media.getLengthStr();

    ret.regEventHandler(
        MouseDownEvent.class,
        (Widget w, MouseDownEvent event) -> {
          if (w.isFocused()) {
            player.startPlay(media);
            gui.postEvent(new UpdateMediaEvent());
          }
        });

    return ret;
  }
コード例 #13
0
 /** Plays the ringtone. */
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:28:26.977 -0500",
     hash_original_method = "F9F3FD902406E9F982D2A30CB15B8CC4",
     hash_generated_method = "D19C91221B1080DB646063B49CD92AD8")
 public void play() {
   if (mAudio == null) {
     try {
       openMediaPlayer();
     } catch (Exception ex) {
       Log.e(TAG, "play() caught ", ex);
       mAudio = null;
     }
   }
   if (mAudio != null) {
     // do not ringtones if stream volume is 0
     // (typically because ringer mode is silent).
     if (mAudioManager.getStreamVolume(mStreamType) != 0) {
       mAudio.start();
     }
   }
 }
コード例 #14
0
  private void init() {
    pageMain = loaded.getWidget("back").copy();

    List<Media> installedMedias = data.getInstalledMediaList();

    player.updatePlayerMedias(installedMedias);

    {
      Widget area = pageMain.getWidget("area");
      ElementList list = new ElementList();

      for (Media m : installedMedias) {
        list.addWidget(createMedia(m));
      }

      area.addComponent(list);
    }

    EventLoader.load(pageMain, this);
    gui.addWidget(pageMain);

    gui.postEvent(new UpdateMediaEvent());
  }
コード例 #15
0
 /** Plays the ringtone. */
 public void play() {
   if (mLocalPlayer != null) {
     // do not play ringtones if stream volume is 0
     // (typically because ringer mode is silent).
     if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes))
         != 0) {
       mLocalPlayer.start();
     }
   } else if (mAllowRemote && (mRemotePlayer != null)) {
     final Uri canonicalUri = mUri.getCanonicalUri();
     try {
       mRemotePlayer.play(mRemoteToken, canonicalUri, mAudioAttributes);
     } catch (RemoteException e) {
       if (!playFallbackRingtone()) {
         Log.w(TAG, "Problem playing ringtone: " + e);
       }
     }
   } else {
     if (!playFallbackRingtone()) {
       Log.w(TAG, "Neither local nor remote playback available");
     }
   }
 }
コード例 #16
0
ファイル: Logo.java プロジェクト: Rviper001/vlcj
 /**
  * Apply the logo to the media player.
  *
  * <p>All previously applied properties will be set on the media player.
  *
  * @param mediaPlayer media player
  */
 public void apply(MediaPlayer mediaPlayer) {
   if (intOpacity != null) {
     mediaPlayer.setLogoOpacity(intOpacity);
   }
   if (floatOpacity != null) {
     mediaPlayer.setLogoOpacity(floatOpacity);
   }
   if (x != null && y != null && x >= 0 && y >= 0) {
     mediaPlayer.setLogoLocation(x, y);
   }
   if (position != null) {
     mediaPlayer.setLogoPosition(position);
   }
   if (file != null) {
     mediaPlayer.setLogoFile(file);
   }
   if (image != null) {
     mediaPlayer.setLogoImage(image);
   }
   if (enable) {
     mediaPlayer.enableLogo(true);
   }
 }
コード例 #17
0
 @GuiCallback("progress")
 public void updateProgress(Widget w, FrameEvent event) {
   MediaInstance mi = player.getPlayingMedia();
   ProgressBar.get(w).progress = mi == null ? 0.0 : (double) mi.getPlayTime() / mi.media.length;
 }
コード例 #18
0
 @GuiCallback("play_time")
 public void updateTime(Widget w, FrameEvent event) {
   MediaInstance mi = player.getPlayingMedia();
   TextBox.get(w).content = mi == null ? "" : Media.getPlayingTime(mi.getPlayTime());
 }
コード例 #19
0
  @GuiCallback("title")
  public void updateTitle(Widget w, UpdateMediaEvent event) {
    MediaInstance mi = player.getPlayingMedia();

    TextBox.get(w).content = mi == null ? "" : mi.media.getDisplayName();
  }
コード例 #20
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#reparentVideo(java.awt.Component)
  */
 public void reparent(MediaPlayer media, java.awt.Canvas canvas) {
   libvlc_exception_t exception = new libvlc_exception_t();
   long drawable = com.sun.jna.Native.getComponentID(canvas);
   libvlc.libvlc_video_reparent(media.getInstance(), drawable, exception);
 }
コード例 #21
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#getVideoWidth()
  */
 public int getWidth(MediaPlayer media) {
   libvlc_exception_t exception = new libvlc_exception_t();
   return libvlc.libvlc_video_get_height(media.getInstance(), exception);
 }
コード例 #22
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#getFullscreen()
  */
 public boolean getFullscreen(MediaPlayer media) {
   libvlc_exception_t exception = new libvlc_exception_t();
   return libvlc.libvlc_get_fullscreen(media.getInstance(), exception) == 1 ? true : false;
 }
コード例 #23
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#destroyVideo()
  */
 public void destroyVideo(MediaPlayer media) {
   libvlc_exception_t exception = new libvlc_exception_t();
   libvlc.libvlc_video_destroy(media.getInstance(), exception);
 }
コード例 #24
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#toggleFullscreen()
  */
 public void toggleFullscreen(MediaPlayer media) {
   libvlc_exception_t exception = new libvlc_exception_t();
   libvlc.libvlc_toggle_fullscreen(media.getInstance(), exception);
 }
コード例 #25
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#setFullscreen(boolean)
  */
 public void setFullscreen(MediaPlayer media, boolean fullscreen) {
   libvlc_exception_t exception = new libvlc_exception_t();
   libvlc.libvlc_set_fullscreen(media.getInstance(), fullscreen ? 1 : 0, exception);
 }
コード例 #26
0
 private void updatePopState() {
   System.out.println(player.isPlaying());
   DrawTexture.get(pageMain.getWidget("pop")).texture =
       (player.isPlaying() && !player.isPaused()) ? T_PAUSE : T_PLAY;
 }
コード例 #27
0
 @GuiCallback("stop")
 public void onStop(Widget w, MouseDownEvent event) {
   player.stop();
   gui.postEvent(new UpdateMediaEvent());
 }
コード例 #28
0
 @Test
 public void play() {
   player.play();
   assertEquals("Playing Sgt. Pepper's Lonely Hearts Club Band by The Beatles\n", log.getLog());
 }
コード例 #29
0
ファイル: Video.java プロジェクト: yjftsjthsd-g/gmote
 /* (non-Javadoc)
  * @see org.videolan.jvlc.VideoIntf#getSnapshot(java.lang.String)
  */
 public void getSnapshot(MediaPlayer media, String filepath, int width, int height) {
   libvlc_exception_t exception = new libvlc_exception_t();
   libvlc.libvlc_video_take_snapshot(media.getInstance(), filepath, width, height, exception);
 }