MediaPlayer的问题无法播放所有音频文件

时间:2018-07-19 13:52:11

标签: android debugging android-mediaplayer

我对MediaPlayer有问题。 我建立了一个由4个活动组成的应用程序,在每个活动中我有一个项目的listView,一旦我点击一个项目它就会播放一个媒体文件。 好吧,它可以正常工作,直到播放了一些音频文件后它不再播放。 我在“运行”日志中遇到此错误。

D/ViewRootImpl@1250751[ColorsActivity]: ViewPostImeInputStage processPointer 0
D/ViewRootImpl@1250751[ColorsActivity]: ViewPostImeInputStage processPointer 1
D/AbsListView: onTouchUp() mTouchMode : 0
V/MediaPlayer-JNI: native_setup
E/MediaPlayer-JNI: JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
                   JNIMediaPlayerFactory: bIsQCMediaPlayerPresent 0
V/MediaPlayer: constructor
V/MediaPlayer: setListener
V/MediaPlayer-JNI: setParameter: key 1400
V/MediaPlayer: MediaPlayer::setParameter(1400)
V/MediaPlayer-JNI: setAudioStreamType: 3
V/MediaPlayer: MediaPlayer::setAudioStreamType
V/MediaPlayer-JNI: set_session_id(): 23689
V/MediaPlayer: MediaPlayer::setAudioSessionId(23689)
V/MediaPlayer-JNI: setDataSourceFD: fd 83
V/MediaPlayer: setDataSource(83, 2623336, 80742)
V/MediaPlayer: setVideoSurfaceTexture
V/MediaPlayer: prepare
V/MediaPlayer: message received msg=200, ext1=10973, ext2=0
W/MediaPlayer: info/warning (10973, 0)
V/MediaPlayer: callback application
V/MediaPlayer: back from callback
V/MediaPlayer: message received msg=1, ext1=0, ext2=0
               prepared
               signal application thread
               callback application
               back from callback
V/MediaPlayer: prepare complete - status=0
D/MediaPlayer: setSubtitleAnchor in MediaPlayer
V/MediaPlayer: invoke 68
V/MediaPlayer-JNI: start
V/MediaPlayer: start
V/MediaPlayer: invoke 68
V/MediaPlayer: message received msg=100, ext1=1, ext2=-19
E/MediaPlayer: error (1, -19)
V/MediaPlayer: callback application
               back from callback
E/MediaPlayer: Error (1,-19)

这是我其中一项活动的代码:

public class NumbersActivity extends AppCompatActivity {
    private MediaPlayer media;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.word_list);
        //create an array of strings
        final ArrayList<Word> words = new ArrayList<Word>();
        words.add(new Word(getString(R.string.one), "lutti", R.drawable.number_one, R.raw.number_one));
        words.add(new Word(getString(R.string.two), "otiiko", R.drawable.number_two, R.raw.number_two));
        words.add(new Word(getString(R.string.three), "tolookosu", R.drawable.number_three, R.raw.number_three));
        words.add(new Word(getString(R.string.four), "oyyisa", R.drawable.number_four, R.raw.number_four));
        words.add(new Word(getString(R.string.five), "massokka", R.drawable.number_five, R.raw.number_five));
        words.add(new Word(getString(R.string.six), "temmokka", R.drawable.number_six, R.raw.number_six));
        words.add(new Word(getString(R.string.seven), "kenekaku", R.drawable.number_seven, R.raw.number_seven));
        words.add(new Word(getString(R.string.eight), "kawinta", R.drawable.number_eight, R.raw.number_eight));
        words.add(new Word(getString(R.string.nine), "wo’e", R.drawable.number_nine, R.raw.number_nine));
        words.add(new Word(getString(R.string.ten), "na’aacha", R.drawable.number_ten, R.raw.number_ten));

        for (int k = 0; k < words.size(); k++) {
            Log.i("NumbersActivity", "At index " + k + "we have : " + words.get(k));
        }
        WordAdapter adapter = new WordAdapter(this, words, R.color.category_numbers);
        ;

        ListView listView = (ListView) findViewById(R.id.list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                releaseMediaPlayer();
                MediaPlayer media = MediaPlayer.create(NumbersActivity.this, words.get(position).getmSongId());
                media.start();
            }
        });
    }
    private void releaseMediaPlayer() {
        // If the media player is not null, then it may be currently playing a sound.
        if (media != null) {
            // Regardless of the current state of the media player, release its resources
            // because we no longer need it.
            media.release();

            // Set the media player back to null. For our code, we've decided that
            // setting the media player to null is an easy way to tell that the media player
            // is not configured to play an audio file at the moment.
            media = null;
        }
    }

    @Override
    protected void onStop() {
        super.onStop();
        releaseMediaPlayer();
    }
}

0 个答案:

没有答案