MediaPlayer:ArrayList错误(1,-19)

时间:2019-03-14 13:22:08

标签: java android arraylist android-mediaplayer

我正在尝试创建一个包含音频文件的数组列表,该列表必须在单击某个按钮时开始。我收到错误 MediaPlayer:错误(1,-19)

这是我的MainObject代码:

the_column

这是我的适配器的代码:

/**
 * Displays text to the user.
 */
public class MainObject {


    //First we Set the Stat of our Class :

    // Audio File Id

    private  int en_AudioResourceID;

    private  int tz_AudioResourceID;

    // Icons Id

    private int imageResourceId;

    // English Translation
    private   String englishTranslation;

    //Tamazight Translation
    private   String tamazightTranslation;

    /**
     * Create a new MainObject Object :
     *
     * @param englishTranslation   is for ENGLISH NUMBERS
     * @param tamazightTranslation is for TAMAZIGHT NUMBERS
     * @param imageResourceId is the drawable Resource id for images assets
     */

    //Constructor
    public MainObject(String englishTranslation, String tamazightTranslation,
                      int imageResourceId ,int en_AudioResourceID, int tz_AudioResourceID) {

        this.imageResourceId = imageResourceId;
        this.englishTranslation = englishTranslation;
        this.tamazightTranslation = tamazightTranslation;
        this.en_AudioResourceID = en_AudioResourceID;
        this.tz_AudioResourceID = tz_AudioResourceID;

    }

    //Getter
    public  String getEnglishTranslation() {
        return englishTranslation;
    }


    public  String getTamazightTranslation() {
        return tamazightTranslation;
    }



    public Integer getImageResourceId(){return imageResourceId;}

    public Integer getEnAudioResourceId(){return en_AudioResourceID;}

    public Integer getTzAudioResourceId(){return tz_AudioResourceID;}

}

最后是我的ColorActivity的代码,其中包含我的ArrayList:

public class ColorsAdapter extends ArrayAdapter<MainObject> {

    // Create ColorsAdapter's Constructor
    public ColorsAdapter(Context context, ArrayList<MainObject> Colors) {
        super(context, 0, Colors);
    }

    //Override GetView Method
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {

        View listItemView = convertView;
        if (listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(R.layout.activities_layout, parent, false);
        }
        //Get The MainObject object at the the exact Position in the list
        MainObject currentColor = getItem(position);


        //find the TextView in the list_item.xml file by ID
        TextView tamazight_item = (TextView) listItemView.findViewById(R.id.tamazight_text_view);
        //find the TextView in the list_item.xml file by ID
        TextView english_item = (TextView) listItemView.findViewById(R.id.english_text_view);

        //find the ImageView in the list_item.xml file by ID
        ImageView icon_item = (ImageView) listItemView.findViewById(R.id.icon_view);

        //find the Icon id from our NumbersObject object and set the Text on the TextView
        icon_item.setImageResource(currentColor.getImageResourceId());


        //find the EnglishTranslation from our MainObject object and set the Text on the TextView
        tamazight_item.setText(currentColor.getEnglishTranslation());

        //find TamazightTranslation from our MainObject object and set the Text on the TextView

        english_item.setText(currentColor.getTamazightTranslation());





        //Return the whole list item Layout
        return listItemView;

    }
}

如您所见,我做了一个Toast来确保我的clicklistener正常工作,但是我的问题出在mediaPlayer上吗?

1 个答案:

答案 0 :(得分:0)

我认为您应该在媒体播放器完成播放后将其释放。启动mediaPlayer后,请尝试以下操作:

mMediaPlayer.start();
mMediaPlayer.setOnCompletionListener(new 
OnCompletionListener() {
    public void onCompletion(MediaPlayer mp) {
        mp.release();

    };
});