我是一个非常初学者,并尝试使用按钮进行我的第一个应用程序,该按钮在按下时会播放声音。
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并显示此消息(如果未设置)。似乎并不在乎您要播放的源是音乐还是视频。不知道他为什么这么做。
不在乎此“异常”。
要删除此异常,请执行以下步骤:
更新了
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/