Android MediaPlayer problems
<p>I am triggering a MediaPlayer to play a sound on a button click. Sometimes, the player will play the whole sound, sometimes it will not. It always cuts off on the end. I read a few threads on here where people were having the same problem, but none of the suggestions worked. For example, someone said that adding a mediaPlayer.onCompletionListener() would fix the issue, but it has not.</p>

<p>Here is the code with the MediaPlayer:</p>

<pre><code>public View getView(int position, View convertView, ViewGroup parent) {



    LayoutInflater inflater = getLayoutInflater();
    View row = inflater.inflate(R.layout.vocab_row, parent, false);

    ImageView playIcon = (ImageView) row
                .findViewById(R.id.blueplay_icon);
TextView vocabWord = (TextView) row
        .findViewById(R.id.vocab_text_word);
TextView vocabMeaning = (TextView) row
        .findViewById(R.id.vocab_text_meaning);

vocabWord.setText(data.get(position).getKey());
vocabMeaning.setText(data.get(position).getDefinition());

final String fileName = "audio/" + data.get(position).getAudio();

// set the click listener for the play button
playIcon.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {

        final MediaPlayer player = new MediaPlayer();
        AssetManager manager = SingleLesson.this.getAssets();
        final AssetFileDescriptor descriptor;

        try {

            descriptor = manager.openFd(fileName);
            long start = descriptor.getStartOffset();
            long end = descriptor.getLength();

            //reset player 
            if (player != null) {
                player.reset();
            }

            player.setDataSource(descriptor.getFileDescriptor(),
                    start, end);

        } catch (IOException e) {
            Log.e("IO EXCEPTION: ", "while getting mp3 assets.");
            e.printStackTrace();
        }

        // set volume
        player.setVolume(100, 100);

        try {
            player.prepare();
        } catch (IllegalStateException e) {
            Log.e("ERROR: ", "media player, illegal state");
            e.printStackTrace();
        } catch (IOException e) {
            Log.e("ERROR: ", "media player, IO exception");
            e.printStackTrace();
        }

        player.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer inPlayer) {
                player.start();
            }
        });

        // called when the file is finished playing
        player.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer player) {
                player.stop();
                player.release();
            }

        });
    }
</code></pre>

<p>This problem is happening on the emulator but not my htc incredible. It also doesn't happen on my girlfriend's moto droid2, but the sounds do have "clicks" in them on the moto droid2. </p>
