当前位置: 首页>>代码示例>>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;未经允许,请勿转载。