android - VLC在此媒体Android上遇到错误

标签 android audio mp3 vlc

我一直在尝试在默认媒体播放器中播放mp3音频文件。从here复制代码我这样写代码

    AlertDialog.Builder dialog = new AlertDialog.Builder(this);

    dialog
            .setCancelable(true)
            .setMessage("File Path: " + path + "\n"
                    + "Duration: " + duration + "\n"
                    + "File Format: " + format + "\n"
                    + "File Status: " + status)
            .setTitle("File Information")
            .setPositiveButton("Play", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Uri uri = null;
                    uri = Uri.parse(toPlay);
                    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
                    intent.setDataAndType(uri, "audio/mp3");
                    startActivity(intent);
                }
            })
            .setNegativeButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            })
            .setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {

                }
            });

其中pathtoPlay等于/mnt/sdcard/MUSIC/Aey Nojwan.mp3
现在,当我按下dialog上的播放按钮时,VLC播放器打开(未从已安装的播放器中选择播放器),并显示带有以下错误的对话框:

VLC encountered an error with this media. Please try refreshing the media library



我尝试卸载VLC,但是这样做之后,dialog上的播放按钮什么也没做。可能是什么问题。

最佳答案

我也遇到了这个问题,使用这种方式以及人们提到的使用ACTION_VIEW的其他方式也没有运气,所以我不得不处理自己,而不是通过默认播放器,我认为VLC无法正确接收Uri路径。
您可以使用MediaPlayer类直接播放音频文件,如下所示

MediaPlayer mediaPlayer;
mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.m_song);
if(!mediaPlayer.isPlaying())
    mediaPlayer.start();

或者,您也可以使用可以同时播放音频和视频的VideoView。实现将像这样
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle b = this.getIntent().getExtras();
    String filePath= b.getString("file_path");

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.videoview);

    video = (VideoView) findViewById(R.id.surface_view);

    video.setVideoURI(Uri.parse(filePath));

    MediaController mediaController = new MediaController(this);
    video.setMediaController(mediaController);
    video.requestFocus();
    video.start();
}



  <VideoView
        android:id="@+id/surface_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:layout_centerVertical="true" />

关于android - VLC在此媒体Android上遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19793151/

相关文章:

android - 高度:<body> 上的 100% 在 Android 网络应用程序中不起作用?

android - 使用 Phonegap : Where do I need to put the sender id and the app id in my project? 在 Android 中推送通知

android - 如何获取联系人列表android中的联系人总数

python - 用python通过麦克风播放mp3文件

java - 将声音文件播放到Skype通话中

python - 使用 python ffmpeg 修剪音频文件

linux - 如何在 bash 脚本中递归地执行 foreach *.mp3 文件?

android - ListView 中的按钮根据最终列表项被错误修改

iphone - iPhone 上音效的最佳格式是什么

c# - WPF 应用程序 mp3 声音文件的相对路径