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


Java MediaPlayer.setVolume方法代码示例

本文整理汇总了Java中android.media.MediaPlayer.setVolume方法的典型用法代码示例。如果您正苦于以下问题:Java MediaPlayer.setVolume方法的具体用法?Java MediaPlayer.setVolume怎么用?Java MediaPlayer.setVolume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaPlayer的用法示例。


在下文中一共展示了MediaPlayer.setVolume方法的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)) {
        mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
        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:MRYangY,项目名称:YZxing,代码行数:17,代码来源: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: 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

示例4: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  try {
    AssetFileDescriptor file = activity.getResources().openRawResourceFd(this.rawBeep);
    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:10045125,项目名称:QrCode,代码行数:22,代码来源:BeepManager.java

示例5: 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

示例6: enableMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private void enableMediaPlayer() {
	mediaPlayer = new MediaPlayer();

	float volume = prefs.getFloat(PreferenceConstants.BELL_VOLUME,
			PreferenceConstants.DEFAULT_BELL_VOLUME);

	mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);

	AssetFileDescriptor file = res.openRawResourceFd(R.raw.bell);
	try {
		mediaPlayer.setLooping(false);
		mediaPlayer.setDataSource(file.getFileDescriptor(), file
				.getStartOffset(), file.getLength());
		file.close();
		mediaPlayer.setVolume(volume, volume);
		mediaPlayer.prepare();
	} catch (IOException e) {
		Log.e(TAG, "Error setting up bell media player", e);
	}
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:TerminalManager.java

示例7: buildMediaPlayer

import android.media.MediaPlayer; //导入方法依赖的package包/类
private MediaPlayer buildMediaPlayer(Context activity,modes mode) {
  MediaPlayer mediaPlayer = new MediaPlayer();
  mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
  mediaPlayer.setOnCompletionListener(this);
  mediaPlayer.setOnErrorListener(this);
  try {
    AssetFileDescriptor file;
    if(mode==modes.SINGLE)
      file = activity.getResources().openRawResourceFd(R.raw.beep);
    else
      file = activity.getResources().openRawResourceFd(R.raw.triplebeep);
    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:crisfg86,项目名称:Zxing-Custom,代码行数:26,代码来源:BeepManager.java

示例8: 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);

  AssetFileDescriptor file = activity.getResources().openRawResourceFd(keepass2android.plugin.qr.R.raw.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:PhilippC,项目名称:keepass2android,代码行数:19,代码来源:BeepManager.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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);

	AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.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:dufangyu1990,项目名称:LeCatApp,代码行数:20,代码来源:BeepManager.java

示例14: 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

示例15: 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() {
        public void onCompletion(MediaPlayer player) {
            player.seekTo(0);
        }
    });

    AssetFileDescriptor file = activity.getResources().openRawResourceFd(R.raw.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:guzhigang001,项目名称:Zxing,代码行数:23,代码来源:BeepManager.java


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