public abstract class AliMediaDownloader
extends java.lang.Object
AliMediaDownloader instance.
2. Set up listeners, such as setOnPreparedListener(OnPreparedListener), setOnProgressListener(OnProgressListener), etc.
3. Call setSaveDir(String) to specify the directory where the downloaded file will be saved.
4. Call prepare(VidAuth) or prepare(VidSts) to asynchronously prepare the media resource.
5. In the AliMediaDownloader.OnPreparedListener.onPrepared(MediaInfo) callback, get the media information and call selectItem(int) to select the track to download.
6. Call start() to begin the download.
7. During the download, monitor progress via AliMediaDownloader.OnProgressListener.
8. When the download is complete, AliMediaDownloader.OnCompletionListener.onCompletion() will be called.
9. After the download is complete (successful or failed), call release() to release the resources occupied by the downloader.| Modifier and Type | Class and Description |
|---|---|
static interface |
AliMediaDownloader.ConvertURLCallback
Callback interface for URL conversion.
|
static interface |
AliMediaDownloader.OnCompletionListener
Callback interface for download completion.
|
static interface |
AliMediaDownloader.OnErrorListener
Callback interface for download errors.
|
static interface |
AliMediaDownloader.OnPreparedListener
Callback interface for when the download preparation is complete.
|
static interface |
AliMediaDownloader.OnProgressListener
Callback interface for download progress.
|
| Constructor and Description |
|---|
AliMediaDownloader() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
deleteFile()
Deletes the downloaded file associated with the current downloader instance.
|
abstract java.lang.String |
getFilePath()
Gets the file path after a successful download.
|
abstract void |
prepare(VidAuth vidAuth)
Prepares the media resource for download using
VidAuth credentials. |
abstract void |
prepare(VidSts vidSts)
Prepares the media resource for download using
VidSts credentials. |
abstract void |
release()
Releases the resources occupied by the downloader instance.
|
abstract void |
selectItem(int index)
Selects an item to download from the list of tracks provided in
MediaInfo. |
static void |
setConvertURLCallback(AliMediaDownloader.ConvertURLCallback callback)
Sets a global URL conversion callback.
|
abstract void |
setDownloaderConfig(DownloaderConfig config)
Sets the downloader configuration.
|
abstract void |
setOnCompletionListener(AliMediaDownloader.OnCompletionListener l)
Sets the listener for download completion.
|
abstract void |
setOnErrorListener(AliMediaDownloader.OnErrorListener l)
Sets the listener for download errors.
|
abstract void |
setOnPreparedListener(AliMediaDownloader.OnPreparedListener l)
Sets the listener for download preparation completion.
|
abstract void |
setOnProgressListener(AliMediaDownloader.OnProgressListener l)
Sets the listener for download progress.
|
abstract void |
setSaveDir(java.lang.String absPath)
Sets the directory where the downloaded file will be saved.
|
abstract void |
start()
Starts the download.
|
abstract void |
stop()
Stops the download.
|
abstract void |
updateSource(VidAuth vidAuth)
Updates the
VidAuth credential information. |
abstract void |
updateSource(VidSts vidSts)
Updates the
VidSts credential information. |
public abstract void setSaveDir(java.lang.String absPath)
prepare(com.aliyun.player.source.VidAuth).absPath - The absolute path of the directory. The application must ensure it has write permissions for this path.public abstract java.lang.String getFilePath()
AliMediaDownloader.OnCompletionListener.onCompletion() callback is received to ensure the returned path is final and valid.
The return value is undefined if called before the download is complete.setOnCompletionListener(OnCompletionListener)public abstract void selectItem(int index)
MediaInfo.
This method must be called after the AliMediaDownloader.OnPreparedListener.onPrepared(MediaInfo) callback and before calling start().index - The index of the track to download in the list returned by MediaInfo.getTrackInfos().AliMediaDownloader.OnPreparedListener.onPrepared(MediaInfo),
MediaInfo.getTrackInfos()public abstract void setOnCompletionListener(AliMediaDownloader.OnCompletionListener l)
l - An instance of the download completion callback interface. Set to null to remove the listener.AliMediaDownloader.OnCompletionListenerpublic abstract void setOnErrorListener(AliMediaDownloader.OnErrorListener l)
l - An instance of the download error callback interface. Set to null to remove the listener.AliMediaDownloader.OnErrorListenerpublic abstract void setOnPreparedListener(AliMediaDownloader.OnPreparedListener l)
l - An instance of the preparation completion callback interface. Set to null to remove the listener.AliMediaDownloader.OnPreparedListenerpublic abstract void setOnProgressListener(AliMediaDownloader.OnProgressListener l)
l - An instance of the download progress callback interface. Set to null to remove the listener.AliMediaDownloader.OnProgressListenerpublic abstract void prepare(VidAuth vidAuth)
VidAuth credentials.
After this is called, the downloader will start parsing the media information. The result will be returned via AliMediaDownloader.OnPreparedListener.onPrepared(MediaInfo) or AliMediaDownloader.OnErrorListener.onError(ErrorInfo).vidAuth - The playback credentials containing Vid and PlayAuth. See VidAuth.setOnPreparedListener(OnPreparedListener),
setOnErrorListener(OnErrorListener)public abstract void prepare(VidSts vidSts)
VidSts credentials.
After this is called, the downloader will start parsing the media information. The result will be returned via AliMediaDownloader.OnPreparedListener.onPrepared(MediaInfo) or AliMediaDownloader.OnErrorListener.onError(ErrorInfo).vidSts - The security credentials containing Vid and STS information. See VidSts.setOnPreparedListener(OnPreparedListener),
setOnErrorListener(OnErrorListener)public abstract void start()
selectItem(int). After calling, download progress will be reported via AliMediaDownloader.OnProgressListener.public abstract void stop()
public abstract void release()
public abstract void updateSource(VidSts vidSts)
VidSts credential information.
When the STS credentials expire, this method can be called to provide new credentials to continue downloading without recreating the downloader.vidSts - The new VidSts credentials. See VidSts.public abstract void updateSource(VidAuth vidAuth)
VidAuth credential information.
When the PlayAuth credentials expire, this method can be called to provide new credentials to continue downloading without recreating the downloader.vidAuth - The new VidAuth credentials. See VidAuth.public abstract void deleteFile()
public abstract void setDownloaderConfig(DownloaderConfig config)
config - The downloader configuration object. See DownloaderConfig.public static void setConvertURLCallback(AliMediaDownloader.ConvertURLCallback callback)
AliMediaDownloader instances. Once set, the URL will be processed through this callback before each download task begins.callback - An instance of the URL conversion callback interface. Set to null to remove the global callback.AliMediaDownloader.ConvertURLCallback