MP3 only once

All your problems with Audio, Video and Images.

MP3 only once

Postby Manic Miner » Mon Feb 23, 2009 10:21 am

Hello,
I have a problem when playing mp3 file. I would like that when you touch the screen, mp3 file plays only once.
Here's my test code:

package com.android.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;

public class test extends Activity
{

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public boolean onTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
MediaPlayer mp = MediaPlayer.create(test.this,R.raw.sound01);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener(){

@Override
public void onCompletion(MediaPlayer arg0) {

}
});

case MotionEvent.ACTION_UP:
return true;

}
return false;
}
}


Thank you for your help.
Manic Miner
User avatar
Manic Miner
Freshman
Freshman
 
Posts: 6
Joined: Mon Feb 23, 2009 10:05 am

Top

Postby Haibane » Wed Feb 25, 2009 9:36 am

The problem is that capturing the motion can only be done by a view. Since you have no view registered for the motion listener your event will never fire. You should get a view (textview, imageview etc.) / or viewgroup and then register it for the event. Then it should work.
User avatar
Haibane
Junior Developer
Junior Developer
 
Posts: 17
Joined: Fri Feb 13, 2009 10:05 am
Location: Klagenfurt, Austria

Postby Manic Miner » Wed Feb 25, 2009 9:29 pm

Tnx.

It helped.
User avatar
Manic Miner
Freshman
Freshman
 
Posts: 6
Joined: Mon Feb 23, 2009 10:05 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 20 guests