Android 我是否超过了MediaPlayer的数量?
我用android Studio制作了一个音板,播放AoE II的39首mp3曲目。一切都很好,除了他们中只有30人在比赛。在构建之间,9个不起作用的版本各不相同。我是否创建了太多的MediaPlayer?还是有什么别的问题 -----主要活动---- -----XML------- 我有39个按钮,但我相信它们不是问题所在Android 我是否超过了MediaPlayer的数量?,android,android-studio,Android,Android Studio,我用android Studio制作了一个音板,播放AoE II的39首mp3曲目。一切都很好,除了他们中只有30人在比赛。在构建之间,9个不起作用的版本各不相同。我是否创建了太多的MediaPlayer?还是有什么别的问题 -----主要活动---- -----XML------- 我有39个按钮,但我相信它们不是问题所在 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layo
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ahh"
android:onClick="playahh">
</Button>
<Button
android:id="@+id/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="playall_hail"
android:text="@string/all_hail">
</Button>
</LinearLayout>
上述操作重复20次,总共有40个按钮,其中1个为空。为什么要一次创建所有媒体播放器?在单击按钮创建媒体播放器时,您是否观察到延迟?不,我没有,它们的响应速度非常快。我解决了这个问题,但还不知道如何解决。基本上,MediaPlayer没有被释放,并且内存不足。你可以打乒乓球……准备好一个媒体播放器,在活动中启动它,同时在后台释放上一个媒体播放器。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="@+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/ahh"
android:onClick="playahh">
</Button>
<Button
android:id="@+id/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="playall_hail"
android:text="@string/all_hail">
</Button>
</LinearLayout>