Example usage for android.media.session PlaybackState STATE_BUFFERING

List of usage examples for android.media.session PlaybackState STATE_BUFFERING

Introduction

In this page you can find the example usage for android.media.session PlaybackState STATE_BUFFERING.

Prototype

int STATE_BUFFERING

To view the source code for android.media.session PlaybackState STATE_BUFFERING.

Click Source Link

Document

State indicating this item is currently buffering and will begin playing when enough data has buffered.

Usage

From source file:com.appdevper.mediaplayer.app.UpnpPlayback.java

@Override
public void play(QueueItem item) {
    try {/*from w w  w  .j a va  2s. c o  m*/
        loadMedia(item.getDescription().getMediaId(), true);
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (Exception e) {
        LogHelper.e(TAG, "Exception loading media ", e, null);
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.orangesoft.jook.CastPlayback.java

@Override
public void play(MediaSession.QueueItem item) {
    try {//from   w  w w  .  j a va2 s  .  c o m
        loadMedia(item.getDescription().getMediaId(), true);
        state = PlaybackState.STATE_BUFFERING;
        if (callback != null)
            callback.onPlaybackStatusChanged(state);
    } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException
            | IllegalArgumentException e) {
        Log.e(TAG, "Exception loading media", e);
        if (callback != null)
            callback.onError(e.getLocalizedMessage());
    }
}

From source file:com.chinaftw.music.CastPlayback.java

@Override
public void play(QueueItem item) {
    try {//from ww w . ja  v  a  2  s .  com
        loadMedia(item.getDescription().getMediaId(), true);
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException e) {
        LogHelper.e(TAG, "Exception loading media ", e, null);
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:robert843.o2.pl.player.CastPlayback.java

@Override
public void play(QueueItem item) {
    try {//from   ww w . j  a  v  a2s. co m
        loadMedia(item.getDescription().getMediaId(), true);
        Log.d("Plajer", "Plaj!!");
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException e) {
        LogHelper.e(TAG, "Exception loading media ", e, null);
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.appdevper.mediaplayer.app.CastPlayback.java

@Override
public void play(QueueItem item) {
    try {//w  ww .  ja  va2  s. co m
        loadMedia(item.getDescription().getMediaId(), true);
        mState = PlaybackState.STATE_BUFFERING;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (TransientNetworkDisconnectionException | NoConnectionException | JSONException
            | IllegalArgumentException e) {
        LogHelper.e(TAG, "Exception loading media ", e, null);
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }
}

From source file:com.appdevper.mediaplayer.app.UpnpPlayback.java

@Override
public void seekTo(int position) {
    if (mCurrentMediaId == null) {
        if (mCallback != null) {
            mCallback.onError("seekTo cannot be calling in the absence of mediaId.");
        }//from   w w w.  j  a  v  a  2  s  .com
        return;
    }
    try {
        if (upnpPlayer.isPlaying()) {
            mState = PlaybackState.STATE_BUFFERING;
        }
        upnpPlayer.toSeek(ModelUtil.toTimeString(position));
        mCurrentPosition = position;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    } catch (Exception e) {
        LogHelper.e(TAG, e, "Exception pausing cast playback");
        if (mCallback != null) {
            mCallback.onError(e.getMessage());
        }
    }

}

From source file:com.example.android.supportv4.media.Playback.java

public void play(QueueItem item) {
    mPlayOnFocusGain = true;//from  w  ww  .  j ava 2 s . c  o  m
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            Log.e(TAG, "Exception playing song", ex);
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.torrenttunes.android.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;/*from  w  w w  . j  av a 2  s  . co  m*/
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider
                .getMusic(MediaIDHelper.extractMusicIDFromMediaID(item.getDescription().getMediaId()));

        String source = track.getString(MusicProvider.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);

            // Starts preparing the media player in the background. When
            // it's done, it will call our OnPreparedListener (that is,
            // the onPrepared() method on this class, since we set the
            // listener to 'this'). Until the media player is prepared,
            // we *cannot* call start() on it!
            mMediaPlayer.prepareAsync();

            // If we are streaming from the internet, we want to hold a
            // Wifi lock, which prevents the Wifi radio from going to
            // sleep while the song is playing.
            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.appdevper.mediaplayer.app.LocalPlayback.java

@Override
public void play(QueueItem item) {
    mPlayOnFocusGain = true;/* w  w w  .j a v a  2 s.c o  m*/
    tryToGetAudioFocus();
    registerAudioNoisyReceiver();
    String mediaId = item.getDescription().getMediaId();
    boolean mediaHasChanged = !TextUtils.equals(mediaId, mCurrentMediaId);
    if (mediaHasChanged) {
        mCurrentPosition = 0;
        mCurrentMediaId = mediaId;
    }

    if (mState == PlaybackState.STATE_PAUSED && !mediaHasChanged && mMediaPlayer != null) {
        configMediaPlayerState();
    } else {
        mState = PlaybackState.STATE_STOPPED;
        relaxResources(false); // release everything except MediaPlayer
        MediaMetadataCompat track = mMusicProvider.getMusic(item.getDescription().getMediaId());

        String source = track.getString(MusicProviderSource.CUSTOM_METADATA_TRACK_SOURCE);

        try {
            createMediaPlayerIfNeeded();

            mState = PlaybackState.STATE_BUFFERING;

            mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mMediaPlayer.setDataSource(source);
            mMediaPlayer.prepareAsync();

            mWifiLock.acquire();

            if (mCallback != null) {
                mCallback.onPlaybackStatusChanged(mState);
            }

        } catch (IOException ex) {
            LogHelper.e(TAG, ex, "Exception playing song");
            if (mCallback != null) {
                mCallback.onError(ex.getMessage());
            }
        }
    }
}

From source file:com.appdevper.mediaplayer.activity.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();/*from ww  w  .j av a 2s .  c o m*/
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackState.STATE_PLAYING: // fall through
                case PlaybackState.STATE_BUFFERING:
                    controls.pause();
                    stopSeekbarUpdate();
                    break;
                case PlaybackState.STATE_PAUSED:
                case PlaybackState.STATE_STOPPED:
                    controls.play();
                    scheduleSeekbarUpdate();
                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(Utils.formatMillis(progress));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopSeekbarUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress());
            scheduleSeekbarUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        updateFromParams(getIntent());
    }

}