use of android.content.res.AssetFileDescriptor in project android-ocr by rmtheis.
the class BeepManager method buildMediaPlayer.
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;
}
use of android.content.res.AssetFileDescriptor in project wechat by motianhuo.
the class CaptureActivity method initBeepSound.
/**
* 扫描正确后的震动声音,如果感觉apk大了,可以删除
*/
private void initBeepSound() {
if (playBeep && mediaPlayer == null) {
// The volume on STREAM_SYSTEM is not adjustable, and users found it
// too loud,
// so we now play on the music stream.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
mediaPlayer = new MediaPlayer();
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.setOnCompletionListener(beepListener);
AssetFileDescriptor file = 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 e) {
mediaPlayer = null;
}
}
}
use of android.content.res.AssetFileDescriptor in project Lazy by l123456789jy.
the class MediaPlayerUtiles method playAudio.
/**
* 播放音频
*/
public static void playAudio(Context mContext, String fileName) {
try {
// 如果正在播放就停止
stopAudio();
AssetManager assetManager = mContext.getAssets();
AssetFileDescriptor afd = assetManager.openFd(fileName);
MediaPlayer mediaPlayer = getMediaPlayer();
mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
// 循环播放
mediaPlayer.setLooping(false);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
mediaPlayer.start();
}
});
} catch (Exception e) {
Log.e("播放音频失败", "");
}
}
use of android.content.res.AssetFileDescriptor in project Aegis by Decad3nce.
the class AlarmService method alarmNotification.
@SuppressWarnings("deprecation")
private void alarmNotification(Context context) {
AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
NotificationManager mManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher, context.getResources().getString(R.string.receiver_alarm_override), System.currentTimeMillis());
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
boolean vibrate = preferences.getBoolean(SMSAlarmFragment.PREFERENCES_ALARM_VIBRATE, Boolean.parseBoolean(context.getResources().getString(R.string.config_default_alarm_vibrate)));
int duration = Integer.parseInt(preferences.getString(SMSAlarmFragment.PREFERENCES_ALARM_DURATION, getResources().getString(R.string.config_default_alarm_duration)));
int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION);
am.setStreamVolume(AudioManager.STREAM_NOTIFICATION, maxVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_RING);
am.setStreamVolume(AudioManager.STREAM_RING, maxVolume, AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE);
Intent i = new Intent(context, AlarmService.class);
i.putExtra("stop", true);
PendingIntent pi = PendingIntent.getService(context, 0, i, 0);
notification.setLatestEventInfo(context, "aeGis", context.getResources().getString(R.string.receiver_alarm_override), pi);
;
if (vibrate) {
notification.vibrate = new long[] { 100, 200, 100, 500 };
}
AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.alarm);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.setLooping(true);
try {
mMediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mMediaPlayer.prepare();
} catch (IOException e) {
stopForeground(true);
mMediaPlayer.release();
return;
}
mMediaPlayer.start();
// Set duration time-out
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
stopMediaPlayer();
stopForeground(true);
}
}, duration * 1000);
notification.flags |= Notification.FLAG_NO_CLEAR;
startForeground(1242, notification);
}
use of android.content.res.AssetFileDescriptor in project webimageloader by lexs.
the class ContentURLConnection method getContentLength.
@Override
public int getContentLength() {
try {
AssetFileDescriptor fd = mResolver.openAssetFileDescriptor(mUri, "r");
long length = fd.getLength();
if (length <= 0 && length <= Integer.MAX_VALUE) {
return (int) length;
}
} catch (IOException e) {
}
return -1;
}
Aggregations