Example #1
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }

    if (mMediaPlayer != null) {
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
    }
    try {
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mIsPrepared = false;
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      mMediaPlayer.setDataSource(mContext, mUri);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      attachMediaController();
    } catch (IOException ex) {
      Log.w("VideoView", "Unable to open content: " + mUri, ex);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w("VideoView", "Unable to open content: " + mUri, ex);
      return;
    }
  }
  public void turnOnRadio(String station) {
    if (mp != null) {
      mp.stop();
      mp.release();
    }
    Logger.d("clock", "turnOnRadio");
    try {
      Logger.d(TAG, "try");
      mp = new MediaPlayer();
      mp.setScreenOnWhilePlaying(true);
      mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
      Logger.d(TAG, "Station---------------------" + station);
      try {
        mp.setDataSource(station);
      } catch (Exception e) {
        Logger.d(TAG, "default radio");
        try {
          mp.setDataSource(Radiostations.stations.get("DLF"));
        } catch (Exception ex) {
          Logger.d(TAG, "f**k this");
        }
      }
      mp.setVolume(0.99f, 0.99f);
      mp.setOnCompletionListener(this);
      mp.setOnPreparedListener(this);
      mp.prepareAsync();

    } catch (Exception ee) {
      Logger.e("Error", "No Stream");
    }
  }
Example #3
0
  @Override
  public void onPrepared(MediaPlayer mp) {

    if (isPrepare) {
      if (playType == PLAY_TYPE_LOD || playType == PLAY_TYPE_ONDEMAND) {
        // TODO 数据库操作 记忆续播
        MPConPlayManager cPm =
            MPConPlayUtils.findConnectionPlay(currentPosition, parentName, getChildName());
        if (cPm != null && cPm.getEpisodePos() == currentPosition && cPm.getPlayIndex() != 0) {
          mp.seekTo(cPm.getPlayIndex());
        }

        mHandler.sendEmptyMessage(SHOW_CONTROL_ANIMATION);
      }

      mp.start();
      isPrepare = false;

      if (mDialog != null && mDialog.isShowing()) {
        mDialog.dismiss();
      }
      // 判断是否是本地播放或在线点播
      if (playType == PLAY_TYPE_LOD || playType == PLAY_TYPE_ONDEMAND) {
        if (mp.isPlaying() && !mSeekBar.isPressed()) {

          mHandler.sendEmptyMessage(UPDATA_PLAY_TIME);
        }
      }

      mProgressBar.setVisibility(View.INVISIBLE);

      mPlayer.setScreenOnWhilePlaying(true);
    }
  }
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }
    // Tell the music playback service to pause
    // TODO: these constants need to be published somewhere in the framework.
    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    getContext().sendBroadcast(i);

    if (mMediaPlayer != null) {
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
    }
    try {
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mIsPrepared = false;
      Log.v(TAG, "reset duration to -1 in openVideo");
      mDuration = -1;
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      if (URLUtil.isAssetUrl(mUri.toString())) { // DST: 20090606 detect asset url
        AssetFileDescriptor afd = null;
        try {
          String path = mUri.toString().substring("file:///android_asset/".length());
          afd = getContext().getAssets().openFd(path);
          mMediaPlayer.setDataSource(
              afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        } finally {
          if (afd != null) {
            afd.close();
          }
        }
      } else {
        setDataSource();
      }
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      attachMediaController();
    } catch (IOException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      return;
    }
  }
Example #5
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }
    // Tell the music playback service to pause
    // TODO: these constants need to be published somewhere in the framework.
    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);

    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);
    try {
      mMediaPlayer = new MediaPlayer();
      if (mAudioSession != 0) {
        mMediaPlayer.setAudioSessionId(mAudioSession);
      } else {
        mAudioSession = mMediaPlayer.getAudioSessionId();
      }
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnInfoListener(mOnInfoListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      mMediaPlayer.setDataSource(mContext, mUri, mHeaders);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      // we don't set the target state here either, but preserve the
      // target state that was there before.
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }
Example #6
0
  private void openVideo() {
    if (mUri == null || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }

    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);
    try {
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mDuration = -1;
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      mMediaPlayer.setDataSource(getContext(), mUri, mHeaders);
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      // we don't set the target state here either, but preserve the
      // target state that was there before.
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalStateException ex) {
      Log.w(TAG, "Unable to open content: " + mUri, ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    }
  }
Example #7
0
  private void openVideo() {
    /*
     * if (mUri == null || mSurfaceHolder == null) { // not ready for
     * playback just yet, will try again later return; }
     */
    if (mInputStream == null || mSurfaceHolder == null) {
      return;
    }
    // Tell the music playback service to pause
    // TODO: these constants need to be published somewhere in the
    // framework.
    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);

    if (mMediaPlayer != null) {
      mMediaPlayer.reset();
      mMediaPlayer.release();
      mMediaPlayer = null;
    }
    try {
      mMediaPlayer = new MediaPlayer();
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mIsPrepared = false;
      Log.v(TAG, "reset duration to -1 in openVideo");
      mDuration = -1;
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;
      // mMediaPlayer.setDataSource(mContext, mUri);
      mMediaPlayer.setDataSource(mInputStream.getFD());
      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();
      attachMediaController();
    } catch (IOException ex) {
      Log.w(TAG, "Unable to open content: " + mInputStream, ex);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w(TAG, "Unable to open content: " + mInputStream, ex);
      return;
    }
  }
  private void createPlayer(SurfaceHolder holder) {
    if (mMediaPlayer != null) {
      destroyPlayer(holder);
    }

    mMediaPlayer = new MediaPlayer();
    mHolder = holder;

    mVideoWidth = 0;
    mVideoHeight = 0;
    mVideoDurationSeconds = 0;

    try {
      mMediaPlayer.setDisplay(mHolder);
      mMediaPlayer.setDataSource(mUrl);

      mMediaPlayer.setScreenOnWhilePlaying(true);

      mMediaPlayer.setOnPreparedListener(this);
      mMediaPlayer.setOnVideoSizeChangedListener(this);
      mMediaPlayer.setOnCompletionListener(this);
      mMediaPlayer.setOnErrorListener(this);
      mMediaPlayer.setOnInfoListener(this);
      mMediaPlayer.setOnBufferingUpdateListener(this);
      mMediaPlayer.setOnSeekCompleteListener(this);

      mMediaPlayer.prepareAsync();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Example #9
0
  private void openVideo() {
    if ((mFd == null && mUri == null) || mSurfaceHolder == null) {
      // not ready for playback just yet, will try again later
      return;
    }
    // Tell the music playback service to pause
    // TODO: these constants need to be published somewhere in the framework.
    Intent i = new Intent("com.android.music.musicservicecommand");
    i.putExtra("command", "pause");
    mContext.sendBroadcast(i);

    // we shouldn't clear the target state, because somebody might have
    // called start() previously
    release(false);
    try {
      mMediaPlayer = new MediaPlayer();
      // TODO: create SubtitleController in MediaPlayer, but we need
      // a context for the subtitle renderers
      final Context context = getContext();
      // final SubtitleController controller = new SubtitleController(context,
      // mMediaPlayer.getMediaTimeProvider(), mMediaPlayer);
      // controller.registerRenderer(new WebVttRenderer(context));
      // mMediaPlayer.setSubtitleAnchor(controller, this);

      if (mAudioSession != 0) {
        mMediaPlayer.setAudioSessionId(mAudioSession);
      } else {
        mAudioSession = mMediaPlayer.getAudioSessionId();
      }
      mMediaPlayer.setOnPreparedListener(mPreparedListener);
      mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
      mMediaPlayer.setOnCompletionListener(mCompletionListener);
      mMediaPlayer.setOnErrorListener(mErrorListener);
      mMediaPlayer.setOnInfoListener(mInfoListener);
      mMediaPlayer.setOnBufferingUpdateListener(mBufferingUpdateListener);
      mCurrentBufferPercentage = 0;

      if (mUri != null) {
        mMediaPlayer.setDataSource(mContext, mUri, mHeaders);
      } else {
        mMediaPlayer.setDataSource(mFd);
      }

      mMediaPlayer.setDisplay(mSurfaceHolder);
      mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
      mMediaPlayer.setScreenOnWhilePlaying(true);
      mMediaPlayer.prepareAsync();

      /*   for (Pair<InputStream, MediaFormat> pending: mPendingSubtitleTracks) {
          try {
              mMediaPlayer.addSubtitleSource(pending.first, pending.second);
          } catch (IllegalStateException e) {
              mInfoListener.onInfo(
                      mMediaPlayer, MediaPlayer.MEDIA_INFO_UNSUPPORTED_SUBTITLE, 0);
          }
      }*/

      // we don't set the target state here either, but preserve the
      // target state that was there before.
      mCurrentState = STATE_PREPARING;
      attachMediaController();
    } catch (IOException ex) {
      Log.w(TAG, "Unable to open content: ", ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } catch (IllegalArgumentException ex) {
      Log.w(TAG, "Unable to open content: ", ex);
      mCurrentState = STATE_ERROR;
      mTargetState = STATE_ERROR;
      mErrorListener.onError(mMediaPlayer, MediaPlayer.MEDIA_ERROR_UNKNOWN, 0);
      return;
    } finally {
      mPendingSubtitleTracks.clear();
    }
  }
  public static void start(Context context, short timeIndex, long actualTime) {
    Notifier.context = context;

    if (timeIndex == CONSTANT.NEXT_FAJR) timeIndex = CONSTANT.FAJR;

    notification = new Notification(R.drawable.icon, "", actualTime);
    notification.tickerText =
        (timeIndex != CONSTANT.SUNRISE ? context.getString(R.string.allahu_akbar) + ": " : "")
            + context.getString(R.string.time_for)
            + " "
            + context.getString(CONSTANT.TIME_NAMES[timeIndex]).toLowerCase();

    int notificationMethod =
        VARIABLE.settings.getInt(
            "notificationMethod" + timeIndex,
            timeIndex == CONSTANT.SUNRISE
                ? CONSTANT.NOTIFICATION_NONE
                : CONSTANT.NOTIFICATION_DEFAULT);
    if (notificationMethod == CONSTANT.NOTIFICATION_NONE
        || (timeIndex == CONSTANT.SUNRISE && !VARIABLE.alertSunrise())) {
      WakeLock.release();
      return;
    }
    stopNotification(); // We put this after since we don't want to clear previous notifications
                        // unless we have to

    int ringerMode =
        ((AudioManager) context.getSystemService(Context.AUDIO_SERVICE)).getRingerMode();
    int callState =
        ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getCallState();
    if ((notificationMethod == CONSTANT.NOTIFICATION_PLAY
            || notificationMethod == CONSTANT.NOTIFICATION_CUSTOM)
        && ringerMode != AudioManager.RINGER_MODE_SILENT
        && ringerMode != AudioManager.RINGER_MODE_VIBRATE
        && callState == TelephonyManager.CALL_STATE_IDLE) {
      notification.tickerText =
          notification.tickerText + " (" + context.getString(R.string.stop) + ")";
      int alarm = R.raw.beep;
      if (timeIndex == CONSTANT.DHUHR
          || timeIndex == CONSTANT.ASR
          || timeIndex == CONSTANT.MAGHRIB
          || timeIndex == CONSTANT.ISHAA) {
        alarm = R.raw.adhan;
      } else if (timeIndex == CONSTANT.FAJR) {
        alarm = R.raw.adhan_fajr;
      }
      if (notificationMethod == CONSTANT.NOTIFICATION_CUSTOM) {
        mediaPlayer =
            MediaPlayer.create(
                context,
                Uri.parse(VARIABLE.settings.getString("notificationCustomFile" + timeIndex, "")));
        try {
          mediaPlayer.getDuration();
        } catch (Exception ex) {
          mediaPlayer = MediaPlayer.create(context, alarm);
          notification.tickerText =
              notification.tickerText
                  + " - "
                  + context.getString(R.string.error_playing_custom_file);
        }
      } else {
        mediaPlayer = MediaPlayer.create(context, alarm);
      }
      mediaPlayer.setScreenOnWhilePlaying(true);
      mediaPlayer.setOnCompletionListener(
          new MediaPlayer.OnCompletionListener() {
            public void onCompletion(MediaPlayer mp) {
              notification.tickerText =
                  notification
                      .tickerText
                      .toString()
                      .replace(" (" + Notifier.context.getString(R.string.stop) + ")", "");
              notification.defaults = 0;
              startNotification(); // New notification won't have the "(Stop)" at the end of it
                                   // since we are done playing
            }
          });
      try {
        mediaPlayer.start();
      } catch (Exception ex) {
        notification.tickerText =
            notification.tickerText + " - " + context.getString(R.string.error_playing_alert);
      }
      notification.defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS;
    } else {
      notification.defaults = Notification.DEFAULT_ALL;
    }
    startNotification();
  }