本文整理汇总了Java中android.media.AudioAttributes.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java AudioAttributes.Builder方法的具体用法?Java AudioAttributes.Builder怎么用?Java AudioAttributes.Builder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.AudioAttributes
的用法示例。
在下文中一共展示了AudioAttributes.Builder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateView
import android.media.AudioAttributes; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_shoot, null);
findview(v);
mUIHandler = new Handler(new InnerCallBack());
//初始化拍照的声音
ringtone = RingtoneManager.getRingtone(getActivity(), Uri.parse
("file:///system/media/audio/ui/camera_click.ogg"));
AudioAttributes.Builder attr = new AudioAttributes.Builder();
attr.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
ringtone.setAudioAttributes(attr.build());
//初始化相机布局
mTextureView.setSurfaceTextureListener(mSurfacetextlistener);
mTextureView.setOnTouchListener(textTureOntuchListener);
return v;
}
示例2: createAlarmChannel
import android.media.AudioAttributes; //导入方法依赖的package包/类
private void createAlarmChannel(String uri) {
Log.e("KCA-A", "recv: " + uri);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String soundKind = getStringPreferences(getApplicationContext(), PREF_KCA_NOTI_SOUND_KIND);
boolean isVibrate = soundKind.equals(getString(R.string.sound_kind_value_mixed)) || soundKind.equals(getString(R.string.sound_kind_value_vibrate));
notificationManager.deleteNotificationChannel(ALARM_CHANNEL_ID);
while (!alarmChannelList.isEmpty()) {
notificationManager.deleteNotificationChannel(alarmChannelList.poll());
}
AudioAttributes.Builder attrs = new AudioAttributes.Builder();
attrs.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION);
attrs.setUsage(AudioAttributes.USAGE_NOTIFICATION);
String channel_name = createAlarmId(uri, isVibrate);
alarmChannelList.add(channel_name);
NotificationChannel channel = new NotificationChannel(alarmChannelList.peek(),
getStringWithLocale(R.string.notification_appinfo_title), NotificationManager.IMPORTANCE_HIGH);
channel.setSound(Uri.parse(uri), attrs.build());
channel.enableVibration(isVibrate);
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
notificationManager.createNotificationChannel(channel);
}
}
示例3: onStart
import android.media.AudioAttributes; //导入方法依赖的package包/类
@Override
protected void onStart() {
super.onStart();
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
ringtone = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);
if (ringtone == null) {
ringtoneUri = RingtoneManager.getValidRingtoneUri(getApplicationContext());
if (ringtoneUri == null) {
Log.e("FindMyPhone", "Could not find a ringtone to play!");
return;
}
ringtone = RingtoneManager.getRingtone(getApplicationContext(), ringtoneUri);
}
if (android.os.Build.VERSION.SDK_INT >= 21) {
AudioAttributes.Builder b = new AudioAttributes.Builder();
b.setUsage(AudioAttributes.USAGE_ALARM);
ringtone.setAudioAttributes(b.build());
} else {
ringtone.setStreamType(AudioManager.STREAM_ALARM);
}
ringtone.play();
}
示例4: onCreate
import android.media.AudioAttributes; //导入方法依赖的package包/类
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
SoundPool.Builder builder = new SoundPool.Builder();
AudioAttributes.Builder attributes = new AudioAttributes.Builder();
attributes.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
.setLegacyStreamType(AudioManager.STREAM_MUSIC)
.setUsage(AudioAttributes.USAGE_ASSISTANCE_ACCESSIBILITY);
builder.setAudioAttributes(attributes.build())
.setMaxStreams(MAX_STREAMS);
mSoundPool = builder.build();
} else {
mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
}
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mLruCache = new LruCache<String, String[]>(Characters.MONOGRAPHS.length);
registerReceiver(mBroadcastReceiver, new IntentFilter(PronounceService.PLAY_PRONOUNCE_NAME));
}
示例5: initSoundPool
import android.media.AudioAttributes; //导入方法依赖的package包/类
private void initSoundPool() {
SoundPool.Builder spb = new SoundPool.Builder();
spb.setMaxStreams(10);
AudioAttributes.Builder attrBuilder = new AudioAttributes.Builder();
attrBuilder.setLegacyStreamType(AudioManager.STREAM_MUSIC);
spb.setAudioAttributes(attrBuilder.build());
soundPool = spb.build();
}
示例6: emitNotification
import android.media.AudioAttributes; //导入方法依赖的package包/类
private void emitNotification(String bigText, String path) {
RemoteViews layout = new RemoteViews(
"uk.co.yahoo.p1rpp.calendartrigger",
R.layout.notification);
layout.setTextViewText(R.id.notificationtext, bigText);
DateFormat df = DateFormat.getTimeInstance(DateFormat.SHORT);
layout.setTextViewText(R.id.notificationtime,
df.format(System.currentTimeMillis()));
Notification.Builder NBuilder
= new Notification.Builder(this)
.setSmallIcon(R.drawable.notif_icon)
.setContentTitle(getString(R.string.mode_sonnerie_change))
.setContent(layout);
if (!path.isEmpty())
{
Uri uri = new Uri.Builder().path(path).build();
AudioAttributes.Builder ABuilder
= new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION);
NBuilder.setSound(uri, ABuilder.build());
}
// Show notification
NotificationManager notifManager = (NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE);
notifManager.notify(notifyId++, NBuilder.build());
}
示例7: register
import android.media.AudioAttributes; //导入方法依赖的package包/类
@Override
public void register(Context context, ComponentName mediaButtonReceiverComponent) {
downloadService = (DownloadService) context;
mediaSession = new MediaSession(downloadService, "DSub MediaSession");
Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON);
mediaButtonIntent.setComponent(mediaButtonReceiverComponent);
PendingIntent mediaPendingIntent = PendingIntent.getBroadcast(context.getApplicationContext(), 0, mediaButtonIntent, 0);
mediaSession.setMediaButtonReceiver(mediaPendingIntent);
Intent activityIntent = new Intent(context, SubsonicFragmentActivity.class);
activityIntent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD, true);
activityIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent activityPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
mediaSession.setSessionActivity(activityPendingIntent);
mediaSession.setFlags(MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS | MediaSession.FLAG_HANDLES_MEDIA_BUTTONS);
mediaSession.setCallback(new EventCallback());
AudioAttributes.Builder audioAttributesBuilder = new AudioAttributes.Builder();
audioAttributesBuilder.setUsage(AudioAttributes.USAGE_MEDIA)
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
mediaSession.setPlaybackToLocal(audioAttributesBuilder.build());
mediaSession.setActive(true);
Bundle sessionExtras = new Bundle();
sessionExtras.putBoolean(WEAR_BACKGROUND_THEME, true);
sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_PREVIOUS, true);
sessionExtras.putBoolean(WEAR_RESERVE_SKIP_TO_NEXT, true);
sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_PREVIOUS, true);
sessionExtras.putBoolean(AUTO_RESERVE_SKIP_TO_NEXT, true);
mediaSession.setExtras(sessionExtras);
imageLoader = SubsonicActivity.getStaticImageLoader(context);
}
示例8: createAudioTrack
import android.media.AudioAttributes; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.M)
protected AudioTrack createAudioTrack() {
AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
boolean doLowLatency = (AudioLatencyTuner.isLowLatencySupported()
&& mLatencyController.isLowLatencyEnabled());
if (doLowLatency) {
Log.i(TAG, "createAudioTrack() using FLAG_LOW_LATENCY");
attributesBuilder.setFlags(AudioLatencyTuner.getLowLatencyFlag());
}
AudioAttributes attributes = attributesBuilder.build();
AudioFormat format = new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_FLOAT)
.setChannelMask(AudioFormat.CHANNEL_OUT_STEREO)
.build();
AudioTrack.Builder builder = new AudioTrack.Builder()
.setAudioAttributes(attributes)
.setAudioFormat(format);
if (doLowLatency) {
// Start with a bigger buffer because we can lower it later.
int bufferSizeInFrames = LOW_LATENCY_BUFFER_CAPACITY_IN_FRAMES;
builder.setBufferSizeInBytes(bufferSizeInFrames * BYTES_PER_FRAME);
}
AudioTrack track = builder.build();
if (track == null) {
throw new RuntimeException("Could not make the Audio Track! attributes = "
+ attributes + ", format = " + format);
}
return track;
}
示例9: setPlaybackToLocal
import android.media.AudioAttributes; //导入方法依赖的package包/类
public static void setPlaybackToLocal(Object sessionObj, int stream) {
// TODO update APIs to use support version of AudioAttributes
AudioAttributes.Builder bob = new AudioAttributes.Builder();
bob.setLegacyStreamType(stream);
((MediaSession) sessionObj).setPlaybackToLocal(bob.build());
}
示例10: createAudioTrack
import android.media.AudioAttributes; //导入方法依赖的package包/类
private AudioTrack createAudioTrack(int channelConfig, int bufferSize, boolean lowLatency) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
return new AudioTrack(AudioManager.STREAM_MUSIC,
48000,
channelConfig,
AudioFormat.ENCODING_PCM_16BIT,
bufferSize,
AudioTrack.MODE_STREAM);
}
else {
AudioAttributes.Builder attributesBuilder = new AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_GAME);
AudioFormat format = new AudioFormat.Builder()
.setEncoding(AudioFormat.ENCODING_PCM_16BIT)
.setSampleRate(48000)
.setChannelMask(channelConfig)
.build();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
// Use FLAG_LOW_LATENCY on L through N
if (lowLatency) {
attributesBuilder.setFlags(AudioAttributes.FLAG_LOW_LATENCY);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AudioTrack.Builder trackBuilder = new AudioTrack.Builder()
.setAudioFormat(format)
.setAudioAttributes(attributesBuilder.build())
.setTransferMode(AudioTrack.MODE_STREAM)
.setBufferSizeInBytes(bufferSize);
// Use PERFORMANCE_MODE_LOW_LATENCY on O and later
if (lowLatency) {
trackBuilder.setPerformanceMode(AudioTrack.PERFORMANCE_MODE_LOW_LATENCY);
}
return trackBuilder.build();
}
else {
return new AudioTrack(attributesBuilder.build(),
format,
bufferSize,
AudioTrack.MODE_STREAM,
AudioManager.AUDIO_SESSION_ID_GENERATE);
}
}
}