gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 02:15:56 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com