當前位置: 首頁>>代碼示例>>Java>>正文


Java AudioAttributes.Builder方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lupwei,項目名稱:Croprotector,代碼行數:19,代碼來源:Shoot_fragment.java

示例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);
    }
}
 
開發者ID:antest1,項目名稱:kcanotify,代碼行數:25,代碼來源:KcaAlarmService.java

示例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();
}
 
開發者ID:KDE,項目名稱:kdeconnect-android,代碼行數:26,代碼來源:FindMyPhoneActivity.java

示例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));
}
 
開發者ID:feelinglucky,項目名稱:Gojuon,代碼行數:24,代碼來源:PronounceService.java

示例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();
}
 
開發者ID:hgs1217,項目名稱:Paper-Melody,代碼行數:9,代碼來源:PlayActivity.java

示例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());
}
 
開發者ID:rparkins999,項目名稱:CalendarTrigger,代碼行數:28,代碼來源:MuteService.java

示例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);
}
 
開發者ID:popeen,項目名稱:Popeens-DSub,代碼行數:36,代碼來源:RemoteControlClientLP.java

示例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;
}
 
開發者ID:philburk,項目名稱:android-midisuite,代碼行數:32,代碼來源:SimpleAudioOutput.java

示例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());
}
 
開發者ID:kingargyle,項目名稱:adt-leanback-support,代碼行數:7,代碼來源:MediaSessionCompatApi21.java

示例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);
        }
    }
}
 
開發者ID:moonlight-stream,項目名稱:moonlight-android,代碼行數:49,代碼來源:AndroidAudioRenderer.java


注:本文中的android.media.AudioAttributes.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。