【问题标题】:VLC encountered an error with this media AndroidVLC 遇到此媒体 Android 错误
【发布时间】:2013-11-16 13:44:38
【问题描述】:

我一直在尝试在默认媒体播放器中播放 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) {

                }
            });

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

VLC 遇到此媒体错误。请尝试刷新 媒体库

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

【问题讨论】:

  • 如果您添加从其他代码中删除的"file:/" 是否有效?
  • 刚刚发生了什么?

标签: android audio mp3 vlc


【解决方案1】:

我也遇到了这个问题,使用这种方式以及人们提到的其他一些使用 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" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-18
    • 1970-01-01
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多