当前位置: 首页>>代码示例>>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;未经允许,请勿转载。