java - 我无法在 Android 中使用 Mediaplayer 类播放 MP3 文件

标签 java android

正如您在图片中看到的,它无法识别 start() 方法:
As you can see in the  image it does not recognizes the start() method

http://prntscr.com/jv12wq

最佳答案

您在方法外部调用 play.start()。这在 Java 中是不允许的。

play.start() 放入方法中(例如 onCreate)

而且,正如 Gabe Sechan 在评论中提到的,创建 MediaPlayer 需要上下文。您提供this,这意味着MediaPlayer的初始化也需要进入onCreate..

关于java - 我无法在 Android 中使用 Mediaplayer 类播放 MP3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50863731/

相关文章:

java - 使用 RxJava 缓冲分组项目

android - fragment 类问题中的多个按钮?

java - if 和 else 语句

android - state as class 是否需要 SatefulWidget?

android - 如何通过单击按钮打开 google play 商店

android - 编辑自定义帐户

java - 使用不同类的方法

java - 如何在 spring 中为运行时动态创建的对象注入(inject)依赖?

java - 当 JPA 中字段为 LocalDateTime 时,如何查找今天创建的每个实例?

java - 几个 View 的同步动画