Dela via


MediaPlayer.SetDataSource Method

Definition

Overloads

SetDataSource(AssetFileDescriptor)

Sets the data source (AssetFileDescriptor) to use.

SetDataSource(MediaDataSource)

Sets the data source (MediaDataSource) to use.

SetDataSource(FileDescriptor)

Sets the data source (FileDescriptor) to use.

SetDataSource(String)

Sets the data source (file-path or http/rtsp URL) to use.

SetDataSource(Context, Uri)

Sets the data source as a content Uri.

SetDataSource(Context, Uri, IDictionary<String,String>)

Sets the data source as a content Uri.

SetDataSource(FileDescriptor, Int64, Int64)

Sets the data source (FileDescriptor) to use.

SetDataSource(Context, Uri, IDictionary<String,String>, IList<HttpCookie>)

Sets the data source as a content Uri.

SetDataSource(AssetFileDescriptor)

Sets the data source (AssetFileDescriptor) to use.

[Android.Runtime.Register("setDataSource", "(Landroid/content/res/AssetFileDescriptor;)V", "GetSetDataSource_Landroid_content_res_AssetFileDescriptor_Handler", ApiSince=24)]
public virtual void SetDataSource (Android.Content.Res.AssetFileDescriptor afd);
[<Android.Runtime.Register("setDataSource", "(Landroid/content/res/AssetFileDescriptor;)V", "GetSetDataSource_Landroid_content_res_AssetFileDescriptor_Handler", ApiSince=24)>]
abstract member SetDataSource : Android.Content.Res.AssetFileDescriptor -> unit
override this.SetDataSource : Android.Content.Res.AssetFileDescriptor -> unit

Parameters

afd
AssetFileDescriptor

the AssetFileDescriptor for the file you want to play

Attributes

Remarks

Sets the data source (AssetFileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.

Java documentation for android.media.MediaPlayer.setDataSource(android.content.res.AssetFileDescriptor).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(MediaDataSource)

Sets the data source (MediaDataSource) to use.

[Android.Runtime.Register("setDataSource", "(Landroid/media/MediaDataSource;)V", "GetSetDataSource_Landroid_media_MediaDataSource_Handler", ApiSince=23)]
public virtual void SetDataSource (Android.Media.MediaDataSource? dataSource);
[<Android.Runtime.Register("setDataSource", "(Landroid/media/MediaDataSource;)V", "GetSetDataSource_Landroid_media_MediaDataSource_Handler", ApiSince=23)>]
abstract member SetDataSource : Android.Media.MediaDataSource -> unit
override this.SetDataSource : Android.Media.MediaDataSource -> unit

Parameters

dataSource
MediaDataSource

the MediaDataSource for the media you want to play

Attributes

Remarks

Sets the data source (MediaDataSource) to use.

Java documentation for android.media.MediaPlayer.setDataSource(android.media.MediaDataSource).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(FileDescriptor)

Sets the data source (FileDescriptor) to use.

[Android.Runtime.Register("setDataSource", "(Ljava/io/FileDescriptor;)V", "GetSetDataSource_Ljava_io_FileDescriptor_Handler")]
public virtual void SetDataSource (Java.IO.FileDescriptor? fd);
[<Android.Runtime.Register("setDataSource", "(Ljava/io/FileDescriptor;)V", "GetSetDataSource_Ljava_io_FileDescriptor_Handler")>]
abstract member SetDataSource : Java.IO.FileDescriptor -> unit
override this.SetDataSource : Java.IO.FileDescriptor -> unit

Parameters

fd
FileDescriptor

the FileDescriptor for the file you want to play

Attributes

Exceptions

if it is called in an invalid state

Remarks

Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.

Java documentation for android.media.MediaPlayer.setDataSource(java.io.FileDescriptor).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(String)

Sets the data source (file-path or http/rtsp URL) to use.

[Android.Runtime.Register("setDataSource", "(Ljava/lang/String;)V", "GetSetDataSource_Ljava_lang_String_Handler")]
public virtual void SetDataSource (string? path);
[<Android.Runtime.Register("setDataSource", "(Ljava/lang/String;)V", "GetSetDataSource_Ljava_lang_String_Handler")>]
abstract member SetDataSource : string -> unit
override this.SetDataSource : string -> unit

Parameters

path
String

the path of the file, or the http/rtsp URL of the stream you want to play

Attributes

Exceptions

if it is called in an invalid state

When path refers to a local file, the file may actually be opened by a process other than the calling application. This implies that the pathname should be an absolute path (as any other process runs with unspecified current working directory), and that the pathname should reference a world-readable file. As an alternative, the application could first open the file for reading, and then use the file descriptor form SetDataSource(FileDescriptor).

Remarks

Sets the data source (file-path or http/rtsp URL) to use.

When path refers to a local file, the file may actually be opened by a process other than the calling application. This implies that the pathname should be an absolute path (as any other process runs with unspecified current working directory), and that the pathname should reference a world-readable file. As an alternative, the application could first open the file for reading, and then use the file descriptor form #setDataSource(FileDescriptor).

Java documentation for android.media.MediaPlayer.setDataSource(java.lang.String).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(Context, Uri)

Sets the data source as a content Uri.

[Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Handler")]
public virtual void SetDataSource (Android.Content.Context context, Android.Net.Uri uri);
[<Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Handler")>]
abstract member SetDataSource : Android.Content.Context * Android.Net.Uri -> unit
override this.SetDataSource : Android.Content.Context * Android.Net.Uri -> unit

Parameters

context
Context

the Context to use when resolving the Uri

uri
Uri

the Content URI of the data you want to play

Attributes

Exceptions

if it is called in an invalid state

Remarks

Sets the data source as a content Uri.

Java documentation for android.media.MediaPlayer.setDataSource(android.content.Context, android.net.Uri).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(Context, Uri, IDictionary<String,String>)

Sets the data source as a content Uri.

[Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;Ljava/util/Map;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Ljava_util_Map_Handler")]
public virtual void SetDataSource (Android.Content.Context context, Android.Net.Uri uri, System.Collections.Generic.IDictionary<string,string>? headers);
[<Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;Ljava/util/Map;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Ljava_util_Map_Handler")>]
abstract member SetDataSource : Android.Content.Context * Android.Net.Uri * System.Collections.Generic.IDictionary<string, string> -> unit
override this.SetDataSource : Android.Content.Context * Android.Net.Uri * System.Collections.Generic.IDictionary<string, string> -> unit

Parameters

context
Context

the Context to use when resolving the Uri

uri
Uri

the Content URI of the data you want to play

headers
IDictionary<String,String>

the headers to be sent together with the request for the data

Attributes

Remarks

Sets the data source as a content Uri.

<strong>Note</strong> that the cross domain redirection is allowed by default, but that can be changed with key/value pairs through the headers parameter with "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value to disallow or allow cross domain redirection.

Java documentation for android.media.MediaPlayer.setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(FileDescriptor, Int64, Int64)

Sets the data source (FileDescriptor) to use.

[Android.Runtime.Register("setDataSource", "(Ljava/io/FileDescriptor;JJ)V", "GetSetDataSource_Ljava_io_FileDescriptor_JJHandler")]
public virtual void SetDataSource (Java.IO.FileDescriptor? fd, long offset, long length);
[<Android.Runtime.Register("setDataSource", "(Ljava/io/FileDescriptor;JJ)V", "GetSetDataSource_Ljava_io_FileDescriptor_JJHandler")>]
abstract member SetDataSource : Java.IO.FileDescriptor * int64 * int64 -> unit
override this.SetDataSource : Java.IO.FileDescriptor * int64 * int64 -> unit

Parameters

fd
FileDescriptor

the FileDescriptor for the file you want to play

offset
Int64

the offset into the file where the data to be played starts, in bytes

length
Int64

the length in bytes of the data to be played

Attributes

Exceptions

if it is called in an invalid state

Remarks

Sets the data source (FileDescriptor) to use. The FileDescriptor must be seekable (N.B. a LocalSocket is not seekable). It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.

Java documentation for android.media.MediaPlayer.setDataSource(java.io.FileDescriptor, long, long).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

SetDataSource(Context, Uri, IDictionary<String,String>, IList<HttpCookie>)

Sets the data source as a content Uri.

[Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;Ljava/util/Map;Ljava/util/List;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Ljava_util_Map_Ljava_util_List_Handler", ApiSince=26)]
public virtual void SetDataSource (Android.Content.Context context, Android.Net.Uri uri, System.Collections.Generic.IDictionary<string,string>? headers, System.Collections.Generic.IList<Java.Net.HttpCookie>? cookies);
[<Android.Runtime.Register("setDataSource", "(Landroid/content/Context;Landroid/net/Uri;Ljava/util/Map;Ljava/util/List;)V", "GetSetDataSource_Landroid_content_Context_Landroid_net_Uri_Ljava_util_Map_Ljava_util_List_Handler", ApiSince=26)>]
abstract member SetDataSource : Android.Content.Context * Android.Net.Uri * System.Collections.Generic.IDictionary<string, string> * System.Collections.Generic.IList<Java.Net.HttpCookie> -> unit
override this.SetDataSource : Android.Content.Context * Android.Net.Uri * System.Collections.Generic.IDictionary<string, string> * System.Collections.Generic.IList<Java.Net.HttpCookie> -> unit

Parameters

context
Context

the Context to use when resolving the Uri

uri
Uri

the Content URI of the data you want to play

headers
IDictionary<String,String>

the headers to be sent together with the request for the data The headers must not include cookies. Instead, use the cookies param.

cookies
IList<HttpCookie>

the cookies to be sent together with the request

Attributes

Remarks

Sets the data source as a content Uri.

To provide cookies for the subsequent HTTP requests, you can install your own default cookie handler and use other variants of setDataSource APIs instead. Alternatively, you can use this API to pass the cookies as a list of HttpCookie. If the app has not installed a CookieHandler already, this API creates a CookieManager and populates its CookieStore with the provided cookies. If the app has installed its own handler already, this API requires the handler to be of CookieManager type such that the API can update the manager’s CookieStore.

<strong>Note</strong> that the cross domain redirection is allowed by default, but that can be changed with key/value pairs through the headers parameter with "android-allow-cross-domain-redirect" as the key and "0" or "1" as the value to disallow or allow cross domain redirection.

Java documentation for android.media.MediaPlayer.setDataSource(android.content.Context, android.net.Uri, java.util.Map<java.lang.String, java.lang.String>, java.util.List<java.net.HttpCookie>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to