当前位置: 首页>>代码示例>>Java>>正文


Java MediaPlayer.setLooping方法代码示例

本文整理汇总了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;
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:BeepManager.java

示例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;
    }
}
 
开发者ID:xiong-it,项目名称:ZXingAndroidExt,代码行数:22,代码来源:BeepManager.java

示例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();
    }
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:20,代码来源:DefaultGifPlayer.java

示例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();
    }
}
 
开发者ID:vrjgamer,项目名称:VVideoBackground,代码行数:26,代码来源:VVideoBackground.java

示例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();
}
 
开发者ID:squareboat,项目名称:Excuser,代码行数:19,代码来源:AudioPlayer.java

示例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();
    }

}
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:22,代码来源:VideoLiveWallpaper.java

示例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();
    }

}
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:18,代码来源:DynamicWallPaper.java

示例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("通知", "播放过程中出现了错误哦");
            }
        }
 
开发者ID:WanAndroid,项目名称:LiveWallPaper,代码行数:21,代码来源:CameraLiveWallpaper.java

示例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;
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:IncomingRinger.java

示例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;
    }
}
 
开发者ID:CoderChoy,项目名称:BarcodeReaderView,代码行数:21,代码来源:BeepManager.java

示例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();
            }
        }
    }
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:21,代码来源:BaseCallActivity.java

示例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();
            }
        }
    }
}
 
开发者ID:hushengjun,项目名称:FastAndroid,代码行数:21,代码来源:BaseCallActivity.java

示例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...
    }
}
 
开发者ID:nirhart,项目名称:shortrain,代码行数:20,代码来源:TutorialFragment.java

示例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;
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:9,代码来源:PlayerService.java

示例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();
    }
}
 
开发者ID:monkeywiiu,项目名称:Discover,代码行数:29,代码来源:JZMediaSystem.java


注:本文中的android.media.MediaPlayer.setLooping方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。