Example usage for android.media AudioAttributes USAGE_MEDIA

List of usage examples for android.media AudioAttributes USAGE_MEDIA

Introduction

In this page you can find the example usage for android.media AudioAttributes USAGE_MEDIA.

Prototype

int USAGE_MEDIA

To view the source code for android.media AudioAttributes USAGE_MEDIA.

Click Source Link

Document

Usage value to use when the usage is media, such as music, or movie soundtracks.

Usage

From source file:MainActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createSoundPoolNew() {
    AudioAttributes audioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
    mSoundPool = new SoundPool.Builder().setAudioAttributes(audioAttributes).setMaxStreams(2).build();
}

From source file:androidx.media.widget.VideoView2.java

public VideoView2(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    mVideoWidth = 0;//from   ww  w .j a  v  a 2 s .  c om
    mVideoHeight = 0;
    mSpeed = 1.0f;
    mFallbackSpeed = mSpeed;
    mSelectedSubtitleTrackIndex = INVALID_TRACK_INDEX;
    // TODO: add attributes to get this value.
    mShowControllerIntervalMs = DEFAULT_SHOW_CONTROLLER_INTERVAL_MS;

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    mAudioAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA)
            .setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();

    // TODO: try to keep a single child at a time rather than always having both.
    mTextureView = new VideoTextureView(getContext());
    mSurfaceView = new VideoSurfaceView(getContext());
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mTextureView.setLayoutParams(params);
    mSurfaceView.setLayoutParams(params);
    mTextureView.setSurfaceListener(this);
    mSurfaceView.setSurfaceListener(this);

    addView(mTextureView);
    addView(mSurfaceView);

    // mSubtitleView = new SubtitleView(getContext());
    // mSubtitleView.setLayoutParams(params);
    // mSubtitleView.setBackgroundColor(0);
    // addView(mSubtitleView);

    boolean enableControlView = (attrs == null) || attrs
            .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableControlView", true);
    if (enableControlView) {
        mMediaControlView = new MediaControlView2(getContext());
    }

    mSubtitleEnabled = (attrs == null) || attrs
            .getAttributeBooleanValue("http://schemas.android.com/apk/res/android", "enableSubtitle", false);

    // TODO: Choose TextureView when SurfaceView cannot be created.
    // Choose surface view by default
    int viewType = (attrs == null) ? VideoView2.VIEW_TYPE_SURFACEVIEW
            : attrs.getAttributeIntValue("http://schemas.android.com/apk/res/android", "viewType",
                    VideoView2.VIEW_TYPE_SURFACEVIEW);
    if (viewType == VideoView2.VIEW_TYPE_SURFACEVIEW) {
        Log.d(TAG, "viewType attribute is surfaceView.");
        mTextureView.setVisibility(View.GONE);
        mSurfaceView.setVisibility(View.VISIBLE);
        mCurrentView = mSurfaceView;
    } else if (viewType == VideoView2.VIEW_TYPE_TEXTUREVIEW) {
        Log.d(TAG, "viewType attribute is textureView.");
        mTextureView.setVisibility(View.VISIBLE);
        mSurfaceView.setVisibility(View.GONE);
        mCurrentView = mTextureView;
    }

    // TODO (b/77158231)
    /*
    MediaRouteSelector.Builder builder = new MediaRouteSelector.Builder();
    builder.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
    builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO);
    builder.addControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO);
    mRouteSelector = builder.build();
    */
}