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


Java AudioAttributes類代碼示例

本文整理匯總了Java中android.media.AudioAttributes的典型用法代碼示例。如果您正苦於以下問題:Java AudioAttributes類的具體用法?Java AudioAttributes怎麽用?Java AudioAttributes使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AudioAttributes類屬於android.media包,在下文中一共展示了AudioAttributes類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: requestAudioFocus

import android.media.AudioAttributes; //導入依賴的package包/類
public boolean requestAudioFocus(OnAudioFocusChangeListener focusChangeListener,
                                 int streamType, int audioFocusGain) {
    int r;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        r = mAudioManager.requestAudioFocus(
                new AudioFocusRequest.Builder(audioFocusGain)
                        .setAudioAttributes(
                                new AudioAttributes.Builder()
                                        .setLegacyStreamType(streamType)
                                        .build())
                        .setOnAudioFocusChangeListener(focusChangeListener)
                        .build());
    } else {
        //noinspection deprecation
        r = mAudioManager.requestAudioFocus(focusChangeListener, streamType, audioFocusGain);
    }

    return r == AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
 
開發者ID:marverenic,項目名稱:Jockey,代碼行數:20,代碼來源:AudioManagerCompat.java

示例2: loadSounds

import android.media.AudioAttributes; //導入依賴的package包/類
protected void loadSounds()
{
    if (null != soundPool) {
        return;
    }

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
    AudioAttributes audioAttributes = new AudioAttributes.Builder()
            .setUsage(AudioAttributes.USAGE_GAME)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
            .build();
    soundPool = new SoundPool.Builder()
            .setMaxStreams(clickers.length + 1)
            .setAudioAttributes(audioAttributes)
            .build();
    for (int i = 0; i < clickers.length; ++i) {
        clickers[i].clickSound = soundPool.load(this, clickers[i].soundId, 1);
    }

    failSound = soundPool.load(this, R.raw.fail, 1);
    successSound = soundPool.load(this, R.raw.success, 1);
}
 
開發者ID:assafnativ,項目名稱:Synesthesia,代碼行數:23,代碼來源:GameActivity.java

示例3: onCreate

import android.media.AudioAttributes; //導入依賴的package包/類
@Override
public void onCreate() {
    super.onCreate();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_DEFAULT_CHANNEL_ID, getString(R.string.notification_channel_name), NotificationManagerCompat.IMPORTANCE_DEFAULT);
        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.createNotificationChannel(notificationChannel);

        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_MEDIA)
                .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                .build();
        audioFocusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN)
                .setOnAudioFocusChangeListener(audioFocusChangeListener)
                .setAcceptsDelayedFocusGain(false)
                .setWillPauseWhenDucked(true)
                .setAudioAttributes(audioAttributes)
                .build();
    }

    audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    mediaSession = new MediaSessionCompat(this, "PlayerService");
    mediaSession.setFlags(MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);
    mediaSession.setCallback(mediaSessionCallback);

    Context appContext = getApplicationContext();

    Intent activityIntent = new Intent(appContext, MainActivity.class);
    mediaSession.setSessionActivity(PendingIntent.getActivity(appContext, 0, activityIntent, 0));

    Intent mediaButtonIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null, appContext, MediaButtonReceiver.class);
    mediaSession.setMediaButtonReceiver(PendingIntent.getBroadcast(appContext, 0, mediaButtonIntent, 0));

    exoPlayer = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(this), new DefaultTrackSelector(), new DefaultLoadControl());
    exoPlayer.addListener(exoPlayerListener);
    DataSource.Factory httpDataSourceFactory = new OkHttpDataSourceFactory(new OkHttpClient(), Util.getUserAgent(this, getString(R.string.app_name)), null);
    Cache cache = new SimpleCache(new File(this.getCacheDir().getAbsolutePath() + "/exoplayer"), new LeastRecentlyUsedCacheEvictor(1024 * 1024 * 100)); // 100 Mb max
    this.dataSourceFactory = new CacheDataSourceFactory(cache, httpDataSourceFactory, CacheDataSource.FLAG_BLOCK_ON_CACHE | CacheDataSource.FLAG_IGNORE_CACHE_ON_ERROR);
    this.extractorsFactory = new DefaultExtractorsFactory();
}
 
開發者ID:SergeyVinyar,項目名稱:AndroidAudioExample,代碼行數:43,代碼來源:PlayerService.java

示例4: initNotificationManager

import android.media.AudioAttributes; //導入依賴的package包/類
private void initNotificationManager() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        final Stopwatch watch = Stopwatch.createStarted();
        final NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

        final NotificationChannel received = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_RECEIVED,
                getString(R.string.notification_channel_received_name), NotificationManager.IMPORTANCE_DEFAULT);
        received.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.coins_received),
                new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION_EVENT).build());
        nm.createNotificationChannel(received);

        final NotificationChannel ongoing = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_ONGOING,
                getString(R.string.notification_channel_ongoing_name), NotificationManager.IMPORTANCE_LOW);
        nm.createNotificationChannel(ongoing);

        final NotificationChannel important = new NotificationChannel(Constants.NOTIFICATION_CHANNEL_ID_IMPORTANT,
                getString(R.string.notification_channel_important_name), NotificationManager.IMPORTANCE_HIGH);
        nm.createNotificationChannel(important);

        log.info("created notification channels, took {}", watch);
    }
}
 
開發者ID:guodroid,項目名稱:okwallet,代碼行數:25,代碼來源:WalletApplication.java

示例5: requestAudioFocus

import android.media.AudioAttributes; //導入依賴的package包/類
private void requestAudioFocus() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        AudioAttributes playbackAttributes = new AudioAttributes.Builder()
                .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
                .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                .build();
        AudioFocusRequest focusRequest =
                new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
                        .setAudioAttributes(playbackAttributes)
                        .setAcceptsDelayedFocusGain(true)
                        .setOnAudioFocusChangeListener(
                                new AudioManager.OnAudioFocusChangeListener() {
                                    @Override
                                    public void onAudioFocusChange(int i) { }
                                })
                        .build();
        audioManager.requestAudioFocus(focusRequest);
    } else {
        audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
                AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    }
}
 
開發者ID:twilio,項目名稱:video-quickstart-android,代碼行數:23,代碼來源:VideoActivity.java

示例6: CreateChannel

import android.media.AudioAttributes; //導入依賴的package包/類
public static void CreateChannel(String identifier, String name, String description, int importance, String soundName, int enableLights, int lightColor, int enableVibration, long[] vibrationPattern, String bundle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        return;

    channels.add(identifier);

    NotificationManager nm = (NotificationManager) UnityPlayer.currentActivity.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationChannel channel = new NotificationChannel(identifier, name, importance);
    channel.setDescription(description);
    if (soundName != null) {
        Resources res = UnityPlayer.currentActivity.getResources();
        int id = res.getIdentifier("raw/" + soundName, null, UnityPlayer.currentActivity.getPackageName());
        AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
        channel.setSound(Uri.parse("android.resource://" + bundle + "/" + id), audioAttributes);
    }
    channel.enableLights(enableLights == 1);
    channel.setLightColor(lightColor);
    channel.enableVibration(enableVibration == 1);
    if (vibrationPattern == null)
        vibrationPattern = new long[] { 1000L, 1000L };
    channel.setVibrationPattern(vibrationPattern);
    nm.createNotificationChannel(channel);
}
 
開發者ID:Agasper,項目名稱:unity-android-notifications,代碼行數:24,代碼來源:UnityNotificationManager.java

示例7: mediaPlayAudioFile

import android.media.AudioAttributes; //導入依賴的package包/類
@Rpc(description = "Play an audio file stored at a specified file path in external storage.")
public void mediaPlayAudioFile(String mediaFilePath) throws IOException {
    mediaReset();
    if (Build.VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        mPlayer.setAudioAttributes(
                new AudioAttributes.Builder()
                        .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
                        .setUsage(AudioAttributes.USAGE_MEDIA)
                        .build());
    } else {
        mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    }
    mPlayer.setDataSource(mediaFilePath);
    mPlayer.prepare(); // Synchronous call blocks until the player is ready for playback.
    mPlayer.start();
}
 
開發者ID:google,項目名稱:mobly-bundled-snippets,代碼行數:17,代碼來源:MediaSnippet.java

示例8: maybePlaySound

import android.media.AudioAttributes; //導入依賴的package包/類
private void maybePlaySound() {
    if (mSoundEnabled &&
            (!mPowerManager.isInteractive() || !mSoundWhenScreenOffOnly)) {
        try {
            final Ringtone sfx = RingtoneManager.getRingtone(mContext,
                    Uri.parse(mSoundUri));
            if (sfx != null) {
                AudioAttributes attrs = new AudioAttributes.Builder()
                        .setUsage(AudioAttributes.USAGE_NOTIFICATION)
                        .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                        .build();
                sfx.setAudioAttributes(attrs);
                sfx.play();
            }
        } catch (Throwable t) {
            XposedBridge.log(t);
        }
    }
}
 
開發者ID:WrBug,項目名稱:GravityBox,代碼行數:20,代碼來源:ProgressBarController.java

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

示例10: createHwAvSyncAudioTrackV21

import android.media.AudioAttributes; //導入依賴的package包/類
/**
 * Instantiates an {@link android.media.AudioTrack} to be used with tunneling video playback.
 */
@TargetApi(21)
private static android.media.AudioTrack createHwAvSyncAudioTrackV21(int sampleRate,
    int channelConfig, int encoding, int bufferSize, int sessionId) {
  AudioAttributes attributesBuilder = new AudioAttributes.Builder()
      .setUsage(AudioAttributes.USAGE_MEDIA)
      .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE)
      .setFlags(AudioAttributes.FLAG_HW_AV_SYNC)
      .build();
  AudioFormat format = new AudioFormat.Builder()
      .setChannelMask(channelConfig)
      .setEncoding(encoding)
      .setSampleRate(sampleRate)
      .build();
  return new android.media.AudioTrack(attributesBuilder, format, bufferSize, MODE_STREAM,
      sessionId);
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:20,代碼來源:AudioTrack.java

示例11: createNotificationChannel

import android.media.AudioAttributes; //導入依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.O)
void createNotificationChannel(Context context) {
    NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence name = MobiComKitConstants.PUSH_NOTIFICATION_NAME;
    ;
    int importance = NotificationManager.IMPORTANCE_HIGH;
    if (mNotificationManager.getNotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION) == null) {
        NotificationChannel mChannel = new NotificationChannel(MobiComKitConstants.AL_PUSH_NOTIFICATION, name, importance);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.GREEN);
        if (ApplozicClient.getInstance(context).isUnreadCountBadgeEnabled()) {
            mChannel.setShowBadge(true);
        } else {
            mChannel.setShowBadge(false);
        }
        if (ApplozicClient.getInstance(context).getVibrationOnNotification()) {
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        }
        AudioAttributes audioAttributes = new AudioAttributes.Builder()
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
                .setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
        mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), audioAttributes);
        mNotificationManager.createNotificationChannel(mChannel);

    }

}
 
開發者ID:AppLozic,項目名稱:Applozic-Android-Chat-Sample,代碼行數:29,代碼來源:RegisterUserClientService.java

示例12: setAudioFocus

import android.media.AudioAttributes; //導入依賴的package包/類
private void setAudioFocus(boolean setFocus) {
    if (audioManager != null) {
        if (setFocus) {
            savedAudioMode = audioManager.getMode();
            // Request audio focus before making any device switch.
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                AudioAttributes playbackAttributes = new AudioAttributes.Builder()
                        .setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION)
                        .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
                        .build();
                AudioFocusRequest focusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
                        .setAudioAttributes(playbackAttributes)
                        .setAcceptsDelayedFocusGain(true)
                        .setOnAudioFocusChangeListener(new AudioManager.OnAudioFocusChangeListener() {
                            @Override
                            public void onAudioFocusChange(int i) {
                            }
                        })
                        .build();
                audioManager.requestAudioFocus(focusRequest);
            } else {
                audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL,
                        AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
            }
            /*
             * Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
             * required to be in this mode when playout and/or recording starts for
             * best possible VoIP performance. Some devices have difficulties with speaker mode
             * if this is not set.
             */
            audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
        } else {
            audioManager.setMode(savedAudioMode);
            audioManager.abandonAudioFocus(null);
        }
    }
}
 
開發者ID:twilio,項目名稱:voice-quickstart-android,代碼行數:38,代碼來源:VoiceActivity.java

示例13: calibrationNotificationCreate

import android.media.AudioAttributes; //導入依賴的package包/類
private void calibrationNotificationCreate(String title, String content, Intent intent, int notificationId) {
    NotificationCompat.Builder mBuilder = notificationBuilder(title, content, intent, NotificationChannels.CALIBRATION_CHANNEL);
    mBuilder.setVisibility(Pref.getBooleanDefaultFalse("public_notifications") ? Notification.VISIBILITY_PUBLIC : Notification.VISIBILITY_PRIVATE);
    mBuilder.setVibrate(vibratePattern);
    mBuilder.setLights(0xff00ff00, 300, 1000);
    if(calibration_override_silent) {
        mBuilder.setSound(Uri.parse(calibration_notification_sound), AudioAttributes.USAGE_ALARM);
    } else {
        mBuilder.setSound(Uri.parse(calibration_notification_sound));
    }



    NotificationManager mNotifyMgr = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
    //mNotifyMgr.cancel(notificationId);
    mNotifyMgr.notify(notificationId, XdripNotificationCompat.build(mBuilder));
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:18,代碼來源:Notifications.java

示例14: AndroidAudioPlayer

import android.media.AudioAttributes; //導入依賴的package包/類
public AndroidAudioPlayer(final AudioConfig audioConfig) {
    AudioAttributes audioAttributes = new AudioAttributes.Builder()
            .setLegacyStreamType(AudioManager.STREAM_MUSIC)
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
            .build();

    AudioFormat audioFormat = new AudioFormat.Builder()
            .setChannelMask(audioConfig.getOutputChannel())
            .setEncoding(audioConfig.getOutputFormat())
            .setSampleRate(audioConfig.getSampleRate())
            .build();

    audioTrack = new AudioTrack(audioAttributes,
            audioFormat,
            audioConfig.getOutputBufferSize(),
            AudioTrack.MODE_STATIC,
            AudioManager.AUDIO_SESSION_ID_GENERATE);

    outputByteCount = audioConfig.getOutputFormatByteCount();
}
 
開發者ID:chRyNaN,項目名稱:Android-Guitar-Tuner,代碼行數:22,代碼來源:AndroidAudioPlayer.java

示例15: getAudioTrack

import android.media.AudioAttributes; //導入依賴的package包/類
AudioTrack getAudioTrack(long bufferSize) {
    AudioFormat audioFormat = getAudioFormat(AudioFormat.CHANNEL_OUT_MONO);
    AudioAttributes attributes = new AudioAttributes.Builder()
            .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
            .setUsage(AudioAttributes.USAGE_MEDIA)
            .build();
    AudioTrack track = new AudioTrack.Builder()
            .setAudioFormat(audioFormat)
            .setBufferSizeInBytes((int) bufferSize)
            .setAudioAttributes(attributes)
            .setTransferMode(AudioTrack.MODE_STREAM)
            .build();
    PresetReverb reverb = getReverb();
    track.attachAuxEffect(reverb.getId());
    track.setAuxEffectSendLevel(1.0f);
    return track;
}
 
開發者ID:StylingAndroid,項目名稱:ChristmasVoice,代碼行數:18,代碼來源:MediaToolsProvider.java


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