Java Code Examples for android.media.MediaPlayer#OnCompletionListener

The following examples show how to use android.media.MediaPlayer#OnCompletionListener . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageAdapter.java    From ChatView with MIT License 6 votes vote down vote up
public MessageAdapter(List<Message> verticalList, Context context,RecyclerView recyclerView) {

        this.messageList = verticalList;
        this.context = context;
        this.filterList = verticalList;
        filter = new MessageFilter(verticalList,this);
        imageLoader = ImageLoader.getInstance();
        typeface = Typeface.createFromAsset(context.getAssets(), "fonts/product_san_regular.ttf");
        mCompletionListener = new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.release();
                mediaPlayer = null;
            }
        };

    }
 
Example 2
Source File: AlertPlugin.java    From microbit with Apache License 2.0 6 votes vote down vote up
private void addInternalPathForPlaying(String rawNameForPlay, MediaPlayer.OnCompletionListener onCompletionListener) {
    int playRawIndex = alertTypes.indexOf(AlertType.TYPE_RAW);

    final PlayAudioPresenter playAudioPresenter;

    if(playRawIndex == -1) {
        playAudioPresenter = new PlayAudioPresenter();
    } else {
        playAudioPresenter = (PlayAudioPresenter) activePresenters.get(playRawIndex);
    }

    playAudioPresenter.setInternalPathForPlay(rawNameForPlay);
    playAudioPresenter.setCallBack(onCompletionListener);

    if(playRawIndex == -1) {
        activePresenters.add(playAudioPresenter);
        alertTypes.add(AlertType.TYPE_RAW);
    }
}
 
Example 3
Source File: RxAudioPlayer.java    From RxAndroidAudio with MIT License 5 votes vote down vote up
/**
 * Non reactive API.
 */
@WorkerThread
public boolean playNonRxy(@NonNull final PlayConfig config,
        final MediaPlayer.OnCompletionListener onCompletionListener,
        final MediaPlayer.OnErrorListener onErrorListener) {
    if (!config.isArgumentValid()) {
        return false;
    }

    try {
        MediaPlayer player = create(config);
        setMediaPlayerListener(player, onCompletionListener, onErrorListener);
        player.setVolume(config.mLeftVolume, config.mRightVolume);
        player.setAudioStreamType(config.mStreamType);
        player.setLooping(config.mLooping);
        if (config.needPrepare()) {
            player.prepare();
        }
        player.start();

        mPlayer = player;
        return true;
    } catch (RuntimeException | IOException e) {
        Log.w(TAG, "startPlay fail, IllegalArgumentException: " + e.getMessage());
        stopPlay();
        return false;
    }
}
 
Example 4
Source File: AndroidMediaPlayerFacade.java    From no-player with Apache License 2.0 5 votes vote down vote up
@Override
public void onCompletion(MediaPlayer mp) {
    currentState = PlaybackState.COMPLETED;
    MediaPlayer.OnCompletionListener onCompletionForwarder = forwarder.onCompletionListener();
    if (onCompletionForwarder == null) {
        throw new IllegalStateException("Should bind a OnCompletionListener. Cannot forward events.");
    }
    onCompletionForwarder.onCompletion(mediaPlayer);
}
 
Example 5
Source File: MediaPlayerImpl.java    From imsdk-android with MIT License 4 votes vote down vote up
protected void playList(long time, String convId, final Context context)
{
    handleVoiceMsgPresenter = new HandleVoiceMsgPresenter();
    handleVoiceMsgPresenter.start(time-1,convId);
    final Runnable runnable = new Runnable() {
        @Override
        public void run() {
            LogUtil.d(TAG, "link play");
            final IMMessage msg = handleVoiceMsgPresenter.next();
            if (msg == null) {
                handleVoiceMsgPresenter.shutdown();
                handleVoiceMsgPresenter = null;
                return;
            }
            TransitSoundJSON json = ChatTextHelper.turnText2SoundObj(msg, false, new ChatTextHelper.DownloadVoiceCallback() {
                @Override
                public void onComplete(boolean isSuccess) {
                    if (isSuccess) {
                        msg.setReadState(MessageStatus.REMOTE_STATUS_CHAT_SUCCESS);

                    } else {
                        msg.setReadState(MessageStatus.REMOTE_STATUS_CHAT_SUCCESS);
                    }
                }
            });

            if (json == null || TextUtils.isEmpty(json.FileName)) {
                player.reset();
            } else {

                File file = new File(json.FileName);
                while (!file.exists())
                {
                    SystemClock.sleep(10);
                }
                reset();
                setResourceFilePath(json.FileName, msg.getId());

                startPlay();
                IMNotificaitonCenter.getInstance().postMainThreadNotificationName(QtalkEvent.Update_Voice_Message,msg);
                EventBus.getDefault().post(new EventBusEvent.UpdateVoiceMessage(msg));
            }

        }
    };
    listener = new MediaPlayer.OnCompletionListener() {//设置播放完成的监听器
        @Override
        public void onCompletion(MediaPlayer mp) {
            LogUtil.d(TAG, "onCompletion");
            overPlay();
            CommonConfig.isPlayVoice = false;
            changeNormalCall(context);
            BackgroundExecutor.execute(runnable,"playvoice_playlist","");

        }
    };
    BackgroundExecutor.execute(runnable,"playvoice_playlist","");
}
 
Example 6
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void onCompletion(MediaPlayer.OnCompletionListener arg) {
  return BaseDSL.attr("onCompletion", arg);
}
 
Example 7
Source File: AndroidMediaPlayerFacadeTest.java    From no-player with Apache License 2.0 4 votes vote down vote up
private void whenCompleted() {
    ArgumentCaptor<MediaPlayer.OnCompletionListener> argumentCaptor = ArgumentCaptor.forClass(MediaPlayer.OnCompletionListener.class);
    verify(mediaPlayer).setOnCompletionListener(argumentCaptor.capture());
    argumentCaptor.getValue().onCompletion(mediaPlayer);
}
 
Example 8
Source File: MediaPlayerForwarder.java    From no-player with Apache License 2.0 4 votes vote down vote up
public MediaPlayer.OnCompletionListener onCompletionListener() {
    return completionListener;
}
 
Example 9
Source File: ScalableVideoView.java    From Android-ScalableVideoView with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(@Nullable MediaPlayer.OnCompletionListener listener) {
    mMediaPlayer.setOnCompletionListener(listener);
}
 
Example 10
Source File: MediaPlayerCompletionListener.java    From no-player with Apache License 2.0 4 votes vote down vote up
void add(MediaPlayer.OnCompletionListener listener) {
    listeners.add(listener);
}
 
Example 11
Source File: VideoView.java    From Spectaculum with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
    this.mOnCompletionListener = l;
}
 
Example 12
Source File: WXVideoView.java    From ucar-weex-core with Apache License 2.0 4 votes vote down vote up
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
  mOnCompletionListener = l;
  if (mVideoView != null) {
    mVideoView.setOnCompletionListener(l);
  }
}
 
Example 13
Source File: NativeSurfaceVideoView.java    From ExoMedia with Apache License 2.0 2 votes vote down vote up
/**
 * Register a callback to be invoked when the end of a media file
 * has been reached during playback.
 *
 * @param listener The callback that will be run
 */
public void setOnCompletionListener(@Nullable MediaPlayer.OnCompletionListener listener) {
    delegate.setOnCompletionListener(listener);
}
 
Example 14
Source File: MainService.java    From android-play-games-in-motion with Apache License 2.0 2 votes vote down vote up
/**
 * Queue a sound into the audio queue.
 * @param uri The Uri of the sound.
 * @param listener The listener to the sound. This is usually MainService but can be overridden.
 */
public void queueSound(Uri uri, MediaPlayer.OnCompletionListener listener) {
    mAudioQueue.offer(new AudioQueueItem(uri, listener));
}
 
Example 15
Source File: NativeTextureVideoView.java    From ExoMedia with Apache License 2.0 2 votes vote down vote up
/**
 * Register a callback to be invoked when the end of a media file
 * has been reached during playback.
 *
 * @param listener The callback that will be run
 */
public void setOnCompletionListener(@Nullable MediaPlayer.OnCompletionListener listener) {
    delegate.setOnCompletionListener(listener);
}
 
Example 16
Source File: NativeVideoDelegate.java    From ExoMedia with Apache License 2.0 2 votes vote down vote up
/**
 * Register a callback to be invoked when the end of a media file
 * has been reached during playback.
 *
 * @param listener The callback that will be run
 */
public void setOnCompletionListener(@Nullable MediaPlayer.OnCompletionListener listener) {
    onCompletionListener = listener;
}
 
Example 17
Source File: XmMp4Player.java    From NewXmPluginSDK with Apache License 2.0 2 votes vote down vote up
/**
 * ApiLevel: 63
 * @param listener
 * @See android.media.MediaPlayer
 */
public void setOnCompletionListener(MediaPlayer.OnCompletionListener listener);
 
Example 18
Source File: AssetVideoView.java    From ResearchStack with Apache License 2.0 2 votes vote down vote up
/**
 * Register a callback to be invoked when the end of a media file has been reached during
 * playback.
 *
 * @param l The callback that will be run
 */
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
    mOnCompletionListener = l;
}
 
Example 19
Source File: MediaVideoViewOld.java    From Slide with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Register a callback to be invoked when the end of a media file
 * has been reached during playback.
 *
 * @param l The callback that will be run
 */
public void setOnCompletionListener(MediaPlayer.OnCompletionListener l) {
    mOnCompletionListener = l;
}
 
Example 20
Source File: IVideoView.java    From jellyfin-androidtv with GNU General Public License v2.0 votes vote down vote up
public void setOnCompletionListener(MediaPlayer.OnCompletionListener listener);