如何在Android中启动默认音乐应用程序以播放特定歌曲?

时间:2017-06-02 12:19:26

标签: android android-intent audio-player android-music-player

我想通过默认媒体播放器播放网址中的特定歌曲

我可以使用Play song on default music player - android

播放它

但它没有完全打开应用程序

此外,我可以使用以下代码打开音乐播放器

Intent intent = Intent.makeMainSelectorActivity(Intent.ACTION_MAIN,Intent.CATEGORY_APP_MUSIC);


startActivity(intent);

我怎么能两个都做?

1 个答案:

答案 0 :(得分:1)

每个制造商都会有其默认音乐播放器,但如果您仍想打开Goog​​le提供的默认Android音乐播放器,即 Google Play音乐,则可以使用以下代码打开它: -

此代码将打开Goog​​le Play音乐,否则会打开其他音乐播放器。

/**
 * This method will help you retrieve properties of a file or a list of files from particular folder in Azure Blob storage
 * @param containerName - Pass the name of the container
 * @param path - Location of your file
 * @param fileName - You can pass complete file name to retrieve one file or you can pass prefix of the file.
 * @return It returns List<BlobProperties> if you pass complete file name, it will return one file or it will find file with supplied prefix.
 * @throws Exception
 */

public List<BlobProperties> retriveBlobFilesProperties(String containerName, String path, String fileName) throws Exception{
    List<BlobProperties> blobFilesProperties = new ArrayList<BlobProperties>();
    CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(this.storageConnectionString);
    CloudBlobClient cloudBlobClient = cloudStorageAccount.createCloudBlobClient();
    CloudBlobContainer cloudBlobContainer = cloudBlobClient.getContainerReference(containerName);
    CloudBlobDirectory directory = cloudBlobContainer.getDirectoryReference(path);
    Iterable<ListBlobItem> blobItems = directory.listBlobs(fileName);
    for(ListBlobItem item : blobItems){
        CloudBlob blob = (CloudBlob)item;
        blobFilesProperties.add(blob.getProperties());
    }
    return blobFilesProperties;
}