1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.net.Uri; 22 23 import java.net.HttpCookie; 24 import java.util.ArrayList; 25 import java.util.HashMap; 26 import java.util.List; 27 import java.util.Map; 28 29 /** 30 * Structure of data source descriptor for sources using URI. 31 * 32 * Used by {@link MediaPlayer2#setDataSource}, {@link MediaPlayer2#setNextDataSource} and 33 * {@link MediaPlayer2#setNextDataSources} to set data source for playback. 34 * 35 * <p>Users should use {@link Builder} to change {@link UriDataSourceDesc}. 36 * @hide 37 */ 38 public class UriDataSourceDesc extends DataSourceDesc { 39 private Uri mUri; 40 private Map<String, String> mHeader; 41 private List<HttpCookie> mCookies; 42 UriDataSourceDesc(String mediaId, long startPositionMs, long endPositionMs, Uri uri, Map<String, String> header, List<HttpCookie> cookies)43 UriDataSourceDesc(String mediaId, long startPositionMs, long endPositionMs, 44 Uri uri, Map<String, String> header, List<HttpCookie> cookies) { 45 super(mediaId, startPositionMs, endPositionMs); 46 mUri = uri; 47 mHeader = header; 48 mCookies = cookies; 49 } 50 51 /** 52 * Return the Uri of this data source. 53 * @return the Uri of this data source 54 */ getUri()55 public @NonNull Uri getUri() { 56 return mUri; 57 } 58 59 /** 60 * Return the Uri headers of this data source. 61 * @return the Uri headers of this data source 62 */ getHeaders()63 public @Nullable Map<String, String> getHeaders() { 64 if (mHeader == null) { 65 return null; 66 } 67 return new HashMap<String, String>(mHeader); 68 } 69 70 /** 71 * Return the Uri cookies of this data source. 72 * @return the Uri cookies of this data source 73 */ getCookies()74 public @Nullable List<HttpCookie> getCookies() { 75 if (mCookies == null) { 76 return null; 77 } 78 return new ArrayList<HttpCookie>(mCookies); 79 } 80 } 81