【问题标题】:How to open external music players (such as Pulsar, Retro Music Players) and play a song which i have selected from my listview?如何打开外部音乐播放器(例如 Pulsar、Retro Music Players)并播放我从列表视图中选择的歌曲?
【发布时间】:2019-01-15 03:45:29
【问题描述】:

我在 listview 中有来自内部存储的歌曲列表,现在我在 onItemClickListener 上添加了以下代码:

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(FileProvider.getUriForFile(parent.getContext(), BuildConfig.APPLICATION_ID + ".provider", file), "audio/*");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    try {
        MainActivity.this.startActivity(intent);
    }
    catch (ActivityNotFoundException e)
    {
        Toast.makeText(parent.getContext(),"Music player not found", Toast.LENGTH_SHORT).show();
    }

它只是打开音乐播放器,不播放所选项目(歌曲)。 现在,我必须做什么才能播放歌曲?

【问题讨论】:

    标签: android listview audio onclicklistener


    【解决方案1】:

    终于,我发现了我的错误,

    我不得不使用

    intent.setDataAndType(Uri.fromFile(file), "audio/*");
    

    而不是

    intent.setDataAndType(FileProvider.getUriForFile(parent.getContext(), BuildConfig.APPLICATION_ID + ".provider", file), "audio/*");
    

    因为“Fileprovider”仅用于从您的应用安装 apk。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-22
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 2012-06-19
      • 1970-01-01
      相关资源
      最近更新 更多