當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaPlayer.setOnCompletionListener方法代碼示例

本文整理匯總了Java中android.media.MediaPlayer.setOnCompletionListener方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaPlayer.setOnCompletionListener方法的具體用法?Java MediaPlayer.setOnCompletionListener怎麽用?Java MediaPlayer.setOnCompletionListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.setOnCompletionListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.qr_sacn);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:coding-dream,項目名稱:TPlayer,代碼行數:22,代碼來源:BeepManager.java

示例2: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:22,代碼來源:BeepManager.java

示例3: playVideo

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void playVideo(Integer Media) {
    doCleanUp();
    try {
        // Create a new media player and set the listeners
        mMediaPlayer = new MediaPlayer();
        mMediaPlayer.setDataSource(path);
        mMediaPlayer.setDisplay(holder);
        mMediaPlayer.prepareAsync();
        mMediaPlayer.setOnBufferingUpdateListener(this);
        mMediaPlayer.setOnCompletionListener(this);
        mMediaPlayer.setOnPreparedListener(this);
        mMediaPlayer.setOnVideoSizeChangedListener(this);
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    } catch (Exception e) {
        Log.e(TAG, "error: " + e.getMessage(), e);
    }
}
 
開發者ID:narenkukreja,項目名稱:quire,代碼行數:18,代碼來源:MediaPlayerActivity.java

示例4: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
	MediaPlayer mediaPlayer = new MediaPlayer();
	mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
	mediaPlayer.setOnCompletionListener(this);
	mediaPlayer.setOnErrorListener(this);
	try {
		AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
		try {
			mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
		} finally {
			file.close();
		}
		mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
		mediaPlayer.prepare();
		return mediaPlayer;
	} catch (IOException ioe) {
		Log.w(TAG, ioe);
		mediaPlayer.release();
		return null;
	}
}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:22,代碼來源:BeepManager.java

示例5: preparePlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void preparePlayer() throws PlayerPrepareException {
    try {
        mediaPlayer = new MediaPlayer();

        mediaPlayer.setDataSource(fileUrl);
        mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
        mediaPlayer.setOnPreparedListener(this);
        mediaPlayer.setOnVideoSizeChangedListener(this);
        mediaPlayer.setOnErrorListener(this);
        mediaPlayer.setOnCompletionListener(this);
        mediaPlayer.setLooping(true);

        changeStatusTo(IGifPlayer.IStatus.PREPARING);
        mediaPlayer.prepareAsync();
    } catch (Exception e) {
        changeStatusTo(IGifPlayer.IStatus.INIT);
        throw new PlayerPrepareException();
    }
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:20,代碼來源:DefaultGifPlayer.java

示例6: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.setOnCompletionListener(this);
    mediaPlayer.setOnErrorListener(this);
    try {
        int rid = activity.getResources().getIdentifier("beep", "raw", activity.getPackageName());
        if (rid == 0) {
            return null;
        }
        AssetFileDescriptor file = activity.getResources().openRawResourceFd(rid);
        try {
            mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        } finally {
            file.close();
        }
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
        return mediaPlayer;
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer.release();
        return null;
    }
}
 
開發者ID:snice,項目名稱:androidscan,代碼行數:26,代碼來源:BeepManager.java

示例7: prepareMediaPlayerFromPoint

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void prepareMediaPlayerFromPoint(int progress) {
  //set mediaPlayer to start from middle of the audio file

  mMediaPlayer = new MediaPlayer();

  try {
    mMediaPlayer.setDataSource(item.getFilePath());
    mMediaPlayer.prepare();
    mSeekBar.setMax(mMediaPlayer.getDuration());
    mMediaPlayer.seekTo(progress);

    mMediaPlayer.setOnCompletionListener(mp -> stopPlaying());
  } catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
  }

  //keep screen on while playing audio
  getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
 
開發者ID:Arjun-sna,項目名稱:Android-AudioRecorder-App,代碼行數:20,代碼來源:PlaybackFragment.java

示例8: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private static MediaPlayer buildMediaPlayer(Context activity) {
    MediaPlayer mediaPlayer = new MediaPlayer();
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    // When the beep has finished playing, rewind to queue up another one.
    mediaPlayer
            .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer player) {
                    player.seekTo(0);
                }
            });

    AssetFileDescriptor file = activity.getResources().openRawResourceFd(
            R.raw.baidu_beep);
    try {
        mediaPlayer.setDataSource(file.getFileDescriptor(),
                file.getStartOffset(), file.getLength());
        file.close();
        mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
        mediaPlayer.prepare();
    } catch (IOException ioe) {
        Log.w(TAG, ioe);
        mediaPlayer = null;
    }
    return mediaPlayer;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:27,代碼來源:BeepManager.java

示例9: PlayController

import android.media.MediaPlayer; //導入方法依賴的package包/類
private PlayController(Context context, AudioFocusManager focusManager, MediaSessionManager sessionManager, NotifyStatusChanged sl, NotifySongChanged sc, NotifyPlayListChanged pl) {
    this.context = context;
    this.focusManager = focusManager;
    this.sessionManager = sessionManager;
    this.mNotifyStatusChanged = sl;
    this.mNotifySongChanged = sc;
    this.mNotifyPlayListChanged = pl;

    mPlayState = STATUS_STOP;
    mPlayer = new MediaPlayer();
    mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            nextSong();
        }
    });

}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:19,代碼來源:PlayController.java

示例10: buildMediaPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);
  try {
	AssetFileDescriptor file = activity.getResources()
			.openRawResourceFd(R.raw.beep);
    try {
      mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
    } finally {
      file.close();
    }
    mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
    mediaPlayer.prepare();
    return mediaPlayer;
  } catch (IOException ioe) {
    Log.w(TAG, ioe);
    mediaPlayer.release();
    return null;
  }
}
 
開發者ID:yun2win,項目名稱:tvConnect_android,代碼行數:23,代碼來源:BeepManager.java

示例11: startPlaying

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void startPlaying() {
  mPlayButton.setImageResource(R.drawable.ic_media_pause);
  mMediaPlayer = new MediaPlayer();

  try {
    mMediaPlayer.setDataSource(item.getFilePath());
    mMediaPlayer.prepare();
    mSeekBar.setMax(mMediaPlayer.getDuration());

    mMediaPlayer.setOnPreparedListener(mp -> mMediaPlayer.start());
  } catch (IOException e) {
    Log.e(LOG_TAG, "prepare() failed");
  }

  mMediaPlayer.setOnCompletionListener(mp -> stopPlaying());

  updateSeekBar();

  //keep screen on while playing audio
  getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}
 
開發者ID:Arjun-sna,項目名稱:Android-AudioRecorder-App,代碼行數:22,代碼來源:PlaybackFragment.java

示例12: startPlay

import android.media.MediaPlayer; //導入方法依賴的package包/類
public void startPlay(String audioPath, TextView timeView) {
    if (!mIsPlaying) {
        if (!StringUtils.isEmpty(audioPath)) {
            mPlayer = new MediaPlayer();
            try {
                mPlayer.setDataSource(audioPath);
                mPlayer.prepare();
                if (timeView != null) {
                    int len = (mPlayer.getDuration() + 500) / 1000;
                    timeView.setText(len + "s");
                }
                mPlayer.start();
                if (listener != null) {
                    listener.starPlay();
                }
                mIsPlaying = true;
                mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        stopPlay();
                    }
                });
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            AppContext.showToastShort(R.string.record_sound_not_found);
        }
    } else {
        stopPlay();
    } // end playing
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:33,代碼來源:RecordButtonUtil.java

示例13: initAudioPlayer

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void initAudioPlayer() throws IOException {
        audioPlay = new MediaPlayer();
//        audioPlay.setOnPreparedListener(prepareListener);
        audioPlay.setOnCompletionListener(endAudioListener);
        audioPlay.setAudioStreamType(AudioManager.STREAM_MUSIC);
        audioPlay.setDataSource(audioFilePath);
        audioPlay.prepare();
    }
 
開發者ID:gvsucis,項目名稱:mobile-app-dev-book,代碼行數:9,代碼來源:AudioActivity.java

示例14: deadListener

import android.media.MediaPlayer; //導入方法依賴的package包/類
private void deadListener(MediaPlayer mMediaPlayer) {
    if (mMediaPlayer != null) {
        mMediaPlayer.setOnSeekCompleteListener(null);
        mMediaPlayer.setOnInfoListener(null);
        mMediaPlayer.setOnPreparedListener(null);
        mMediaPlayer.setOnVideoSizeChangedListener(null);
        mMediaPlayer.setOnCompletionListener(null);
        mMediaPlayer.setOnErrorListener(null);
        mMediaPlayer.setOnBufferingUpdateListener(null);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:12,代碼來源:VideoViewTV.java

示例15: setDataSourceImpl

import android.media.MediaPlayer; //導入方法依賴的package包/類
/**
 * @param player The {@link MediaPlayer} to use
 * @param path   The path of the file, or the http/rtsp URL of the stream
 *               you want to play
 * @return True if the <code>player</code> has been prepared and is
 * ready to play, false otherwise
 */
private boolean setDataSourceImpl(@NonNull final MediaPlayer player, @NonNull final String path) {
    if (context == null) {
        return false;
    }
    try {
        player.reset();
        player.setOnPreparedListener(null);
        if (path.startsWith("content://")) {
            player.setDataSource(context, Uri.parse(path));
        } else {
            player.setDataSource(path);
        }
        player.setAudioStreamType(AudioManager.STREAM_MUSIC);
        player.prepare();
    } catch (Exception e) {
        return false;
    }
    player.setOnCompletionListener(this);
    player.setOnErrorListener(this);
    final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
    intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, getAudioSessionId());
    intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
    intent.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
    context.sendBroadcast(intent);
    return true;
}
 
開發者ID:h4h13,項目名稱:RetroMusicPlayer,代碼行數:34,代碼來源:MultiPlayer.java


注:本文中的android.media.MediaPlayer.setOnCompletionListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。