Search in sources :

Example 1 with AttachmentServer

use of org.thoughtcrime.securesms.attachments.AttachmentServer in project Signal-Android by WhisperSystems.

the class VideoPlayer method setVideoSource.

public void setVideoSource(@NonNull MasterSecret masterSecret, @NonNull VideoSlide videoSource) throws IOException {
    if (this.attachmentServer != null) {
        this.attachmentServer.stop();
    }
    if (videoSource.getUri() != null && PartAuthority.isLocalUri(videoSource.getUri())) {
        Log.w(TAG, "Starting video attachment server for part provider Uri...");
        this.attachmentServer = new AttachmentServer(getContext(), masterSecret, videoSource.asAttachment());
        this.attachmentServer.start();
        this.videoView.setVideoURI(this.attachmentServer.getUri());
    } else if (videoSource.getUri() != null) {
        Log.w(TAG, "Playing video directly from non-local Uri...");
        this.videoView.setVideoURI(videoSource.getUri());
    } else {
        Toast.makeText(getContext(), getContext().getString(R.string.VideoPlayer_error_playing_video), Toast.LENGTH_LONG).show();
        return;
    }
    this.videoView.start();
}
Also used : AttachmentServer(org.thoughtcrime.securesms.attachments.AttachmentServer)

Example 2 with AttachmentServer

use of org.thoughtcrime.securesms.attachments.AttachmentServer in project Signal-Android by WhisperSystems.

the class AudioSlidePlayer method play.

public void play(final double progress) throws IOException {
    if (this.mediaPlayer != null)
        return;
    this.mediaPlayer = new MediaPlayer();
    this.audioAttachmentServer = new AttachmentServer(context, masterSecret, slide.asAttachment());
    audioAttachmentServer.start();
    mediaPlayer.setDataSource(context, audioAttachmentServer.getUri());
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {

        @Override
        public void onPrepared(MediaPlayer mp) {
            Log.w(TAG, "onPrepared");
            synchronized (AudioSlidePlayer.this) {
                if (mediaPlayer == null)
                    return;
                if (progress > 0) {
                    mediaPlayer.seekTo((int) (mediaPlayer.getDuration() * progress));
                }
                mediaPlayer.start();
                setPlaying(AudioSlidePlayer.this);
            }
            notifyOnStart();
            progressEventHandler.sendEmptyMessage(0);
        }
    });
    mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {

        @Override
        public void onCompletion(MediaPlayer mp) {
            Log.w(TAG, "onComplete");
            synchronized (AudioSlidePlayer.this) {
                mediaPlayer = null;
                if (audioAttachmentServer != null) {
                    audioAttachmentServer.stop();
                    audioAttachmentServer = null;
                }
            }
            notifyOnStop();
            progressEventHandler.removeMessages(0);
        }
    });
    mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            Log.w(TAG, "MediaPlayer Error: " + what + " , " + extra);
            Toast.makeText(context, R.string.AudioSlidePlayer_error_playing_audio, Toast.LENGTH_SHORT).show();
            synchronized (AudioSlidePlayer.this) {
                mediaPlayer = null;
                if (audioAttachmentServer != null) {
                    audioAttachmentServer.stop();
                    audioAttachmentServer = null;
                }
            }
            notifyOnStop();
            progressEventHandler.removeMessages(0);
            return true;
        }
    });
    mediaPlayer.prepareAsync();
}
Also used : AttachmentServer(org.thoughtcrime.securesms.attachments.AttachmentServer) MediaPlayer(android.media.MediaPlayer)

Aggregations

AttachmentServer (org.thoughtcrime.securesms.attachments.AttachmentServer)2 MediaPlayer (android.media.MediaPlayer)1