android - MediaPlayer提供错误(262,0)

标签 android button audio

我是一个非常初学者,并尝试使用按钮进行我的第一个应用程序,该按钮在按下时会播放声音。

E/MediaPlayer: Should have subtitle controller already set

E/MediaPlayer: Error (262,0)


当我第二次点击按钮时:

E/MediaPlayer: Error (-38,0)


这些是我通过此简单代码得到的错误:
public class MainActivity extends AppCompatActivity {protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final MediaPlayer m1 = MediaPlayer.create(getApplicationContext(), R.raw.s1);
    Button b1 = (Button) findViewById(R.id.s1);
    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            m1.start();
        }
    });}
“s1.mp3”位于原始文件夹中,大约3-4秒,我认为这不是问题...
我不明白自己在做什么错-在线教程教了我所有这些,有一个类似的代码...
正如我所说,请帮助我,我是一名初学者,所以我需要帮助...
先感谢您!
更新:
public class MainActivity extends AppCompatActivity {
MediaPlayer m1;
protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    m1 = MediaPlayer.create(MainActivity.this, R.raw.s1);
    Button b1 = (Button) findViewById(R.id.s1);
    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            m1.start();
        }
    });}
 }

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.antiriad7.zviadi.MainActivity"
android:orientation="vertical">
<LinearLayout
    android:layout_height="0dp"
    android:layout_width="fill_parent"
    android:layout_weight="25"
    android:id="@+id/l1">
    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S1"
        android:id="@+id/s1"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="34"
        android:text="S2"
        android:id="@+id/s2"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S3"
        android:id="@+id/s3"
        android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="25"
    android:layout_below="@+id/l1"
    android:id="@+id/l2">

    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S4"
        android:id="@+id/s4"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="34"
        android:text="S5"
        android:id="@+id/s5"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S6"
        android:id="@+id/s6"
        android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_below="@+id/l2"
    android:layout_weight="25"
    android:id="@+id/l3">

    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S7"
        android:id="@+id/s7"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="34"
        android:text="S8"
        android:id="@+id/s8"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S9"
        android:id="@+id/s9"
        android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_below="@+id/l3"
    android:layout_weight="25"
    android:id="@+id/l4">

    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S10"
        android:id="@+id/s10"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="34"
        android:text="S11"
        android:id="@+id/s11"
        android:layout_height="match_parent" />
    <Button
        android:layout_width="0dp"
        android:layout_weight="33"
        android:text="S12"
        android:id="@+id/s12"
        android:layout_height="match_parent" />
</LinearLayout>
</LinearLayout>

最佳答案

当MediaPlayer开始播放音乐时,它将检查是否有SubtitleController并显示此消息(如果未设置)。似乎并不在乎您要播放的源是音乐还是视频。不知道他为什么这么做。

不在乎此“异常”。

要删除此异常,请执行以下步骤:

  • 右键单击轨道(您的原始文件夹.mp3文件)
  • ,然后选择属性
  • 选择详细信息
  • ,然后在字幕
  • 上插入歌曲文本(标题)
  • 完成

  • 更新了
    public class MainActivity extends AppCompatActivity {
    
    Mediaplayer m1; 
    
    protected void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    m1 = MediaPlayer.create(MainActivity.this, R.raw.s1);
    Button b1 = (Button) findViewById(R.id.s1);
    b1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            m1.start();
        }
    });}
    

    我希望这个对你有用

    关于android - MediaPlayer提供错误(262,0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39931384/

    相关文章:

    linux - 错误 : pipeline could not be constructed: no element "audiotestsrc"

    android - 计时器格式更改为 0 :0 to 00:00?

    android - 使用按钮单击和滚动进行水平页面交换 - Flutter

    html - 是否可以在类型编号的输入中添加加号/减号按钮?

    javascript - 如何才能使输入字段为空时按钮不执行任何操作?

    c# - 使用 Naudio 复制 Wave 文件 - 复制/附加最新的可用字节

    android - 在 camera2 上使用闪光灯拍照会出现 "after"闪光灯(即没有闪光灯)

    android - 让 Glide 作为所有类的单例工作

    css - 以相反的方向旋转 div 和文本,同时保持它们对齐?

    javascript - 实时播放多种格式的声音