本文整理汇总了Java中android.media.MediaPlayer.setLooping方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.setLooping方法的具体用法?Java MediaPlayer.setLooping怎么用?Java MediaPlayer.setLooping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.MediaPlayer
的用法示例。
在下文中一共展示了MediaPlayer.setLooping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setOnErrorListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例2: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setOnErrorListener(this);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
Log.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例3: 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();
}
}
示例4: surfaceCreated
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (bgVideo != 0) {
mp = new MediaPlayer();
AssetFileDescriptor afd = context.getResources().openRawResourceFd(bgVideo);
try {
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength());
mp.prepare();
} catch (IOException e) {
e.printStackTrace();
}
int videoWidth = mp.getVideoWidth();
int videoHeight = mp.getVideoHeight();
int screenHeight = getHeight();
android.view.ViewGroup.LayoutParams lp = getLayoutParams();
lp.height = screenHeight;
setLayoutParams(lp);
mp.setDisplay(getHolder());
mp.setLooping(true);
mp.start();
}
}
示例5: playProgressTone
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void playProgressTone() {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_RING);
int maxVolume = 100;
final float volume = (float) (1 - (Math.log(maxVolume - 1) / Math.log(maxVolume)));
mPlayer.setVolume(volume, volume);
try {
//mPlayer.setDataSource(mContext, Uri.parse("android.resource://" + mContext.getPackageName() + "/" + R.raw.phone_loud1));
mPlayer.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "Could not setup media player for ringtone");
mPlayer = null;
return;
}
mPlayer.setLooping(true);
mPlayer.start();
}
示例6: onSurfaceCreated
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onSurfaceCreated(SurfaceHolder holder) {
L.d("VideoEngine#onSurfaceCreated ");
super.onSurfaceCreated(holder);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setSurface(holder.getSurface());
try {
AssetManager assetMg = getApplicationContext().getAssets();
AssetFileDescriptor fileDescriptor = assetMg.openFd("test1.mp4");
mMediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartOffset(), fileDescriptor.getLength());
mMediaPlayer.setLooping(true);
mMediaPlayer.setVolume(0, 0);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: initMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private void initMediaPlayer(SurfaceHolder holder){
mediaPlayer = new MediaPlayer();
try {
AssetManager assetMg = getApplicationContext().getAssets();
AssetFileDescriptor fileDescriptor = assetMg.openFd(此处资源asset请从鸿洋大神那获取);
mediaPlayer.setDataSource(fileDescriptor.getFileDescriptor(),
fileDescriptor.getStartOffset(), fileDescriptor.getLength());
mediaPlayer.setDisplay(holder);
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
mediaPlayer.setVolume(0, 0);
mediaPlayer.prepare();
}catch (Exception e){
e.printStackTrace();
}
}
示例8: play
import android.media.MediaPlayer; //导入方法依赖的package包/类
/**
* 播放
*/
private void play(SurfaceHolder surfaceHolder,String videoPath){
mediaPlayer = new MediaPlayer();
// 设置多媒体流类型
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
// 设置用于展示mediaPlayer的容器
mediaPlayer.setSurface(surfaceHolder.getSurface());
// mediaPlayer.setDisplay(surfaceHolder);//用这个方法会报 Wallpapers do not support keep screen on
try {
mediaPlayer.setDataSource(videoPath);
mediaPlayer.prepare();
mediaPlayer.start();
mediaPlayer.setLooping(true);
} catch (Exception e) {
Log.i("通知", "播放过程中出现了错误哦");
}
}
示例9: createPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer createPlayer() {
try {
MediaPlayer mediaPlayer = new MediaPlayer();
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mediaPlayer.setOnErrorListener(new MediaPlayerErrorListener());
mediaPlayer.setDataSource(context, ringtoneUri);
mediaPlayer.setLooping(true);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_RING);
return mediaPlayer;
} catch (IOException e) {
Log.e(TAG, "Failed to create player for incoming call ringer");
return null;
}
}
示例10: buildMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer() {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
AssetFileDescriptor file = context.getResources().openRawResourceFd(R.raw.beep);
try {
mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
} finally {
file.close();
}
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
mediaPlayer.setVolume(BEEP_VOLUME, BEEP_VOLUME);
mediaPlayer.prepare();
return mediaPlayer;
} catch (IOException ioe) {
LogEx.w(TAG, ioe);
mediaPlayer.release();
return null;
}
}
示例11: onIncomingCallRinging
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void onIncomingCallRinging() {
int ringerMode = NotificationUtil.getRingerMode(this);
if(ringerMode != AudioManager.RINGER_MODE_SILENT){
if(ringerMode == AudioManager.RINGER_MODE_VIBRATE){
mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
mVibrator.vibrate(new long[] {500, 1000}, 0);
} else {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, uri);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例12: onIncomingCallRinging
import android.media.MediaPlayer; //导入方法依赖的package包/类
public void onIncomingCallRinging() {
int ringerMode = NotificationUtil.getRingerMode(this);
if (ringerMode != AudioManager.RINGER_MODE_SILENT) {
if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
mVibrator = (Vibrator) RongContext.getInstance().getSystemService(Context.VIBRATOR_SERVICE);
mVibrator.vibrate(new long[]{500, 1000}, 0);
} else {
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
mMediaPlayer = new MediaPlayer();
try {
mMediaPlayer.setDataSource(this, uri);
mMediaPlayer.setLooping(true);
mMediaPlayer.prepare();
mMediaPlayer.start();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
示例13: onSurfaceTextureAvailable
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
Surface s = new Surface(surface);
int movieId = getArguments().getInt(MOVIE_RES_ID);
try {
mediaPlayer = new MediaPlayer();
String path = "android.resource://" + getContext().getPackageName() + "/" + movieId;
mediaPlayer.setDataSource(getContext(), Uri.parse(path));
mediaPlayer.setSurface(s);
mediaPlayer.prepare();
mediaPlayer.setLooping(true);
if (isVisible()) {
videoIsVisibleToUser();
}
} catch (Exception ignore) {
// This is an experiment...
}
}
示例14: getNewMediaPlayer
import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer getNewMediaPlayer() throws IOException {
MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(this, Uri.parse(url));
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setLooping(false);
return mediaPlayer;
}
示例15: prepare
import android.media.MediaPlayer; //导入方法依赖的package包/类
@Override
public void prepare() {
try {
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
if (dataSourceObjects.length > 1) {
mediaPlayer.setLooping((boolean) dataSourceObjects[1]);
}
mediaPlayer.setOnPreparedListener(JZMediaSystem.this);
mediaPlayer.setOnCompletionListener(JZMediaSystem.this);
mediaPlayer.setOnBufferingUpdateListener(JZMediaSystem.this);
mediaPlayer.setScreenOnWhilePlaying(true);
mediaPlayer.setOnSeekCompleteListener(JZMediaSystem.this);
mediaPlayer.setOnErrorListener(JZMediaSystem.this);
mediaPlayer.setOnInfoListener(JZMediaSystem.this);
mediaPlayer.setOnVideoSizeChangedListener(JZMediaSystem.this);
Class<MediaPlayer> clazz = MediaPlayer.class;
Method method = clazz.getDeclaredMethod("setDataSource", String.class, Map.class);
if (dataSourceObjects.length > 2) {
method.invoke(mediaPlayer, currentDataSource.toString(), dataSourceObjects[2]);
} else {
method.invoke(mediaPlayer, currentDataSource.toString(), null);
}
mediaPlayer.prepareAsync();
} catch (Exception e) {
e.printStackTrace();
}
}