在动画 imageview 时播放声音,当 imageview 动画停止时应该停止
Play sound while animating imageview and should stop when imageview animation is stopped
有什么解决方案可以让我在 imageView
播放动画时播放声音。
我试过这个:
public void bounceInterpolar(View thumbnailView){
ImageView animatedImage = (ImageView) findViewById(R.id.img_animation);
Animation animation
= AnimationUtils.loadAnimation(this, R.anim.animation);
animatedImage.startAnimation(animation);
mp = MediaPlayer.create(this, R.raw.soho);
animatedImage = (ImageView)this.findViewById(R.id.img_animation);
animatedImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mp.start();
}
});
问题:通过单击 imageView
,动画结束后,如果我第二次单击 imageView
,则会播放声音,这不是我的要求。需要与动画一起播放声音。
您需要为动画添加监听器。
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mp.start();
}
@Override
public void onAnimationEnd(Animation animation) {
mp.stop();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
请为您的动画对象设置动画侦听器
animation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
}
@Override
public void onAnimationRepeat(Animation animation)
{
}
@Override
public void onAnimationEnd(Animation animation)
{
if (m_player != null && m_player.isPlaying())
{
m_player.stop();
m_player.release();
m_player = null;
}
}
});
有什么解决方案可以让我在 imageView
播放动画时播放声音。
我试过这个:
public void bounceInterpolar(View thumbnailView){
ImageView animatedImage = (ImageView) findViewById(R.id.img_animation);
Animation animation
= AnimationUtils.loadAnimation(this, R.anim.animation);
animatedImage.startAnimation(animation);
mp = MediaPlayer.create(this, R.raw.soho);
animatedImage = (ImageView)this.findViewById(R.id.img_animation);
animatedImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mp.start();
}
});
问题:通过单击 imageView
,动画结束后,如果我第二次单击 imageView
,则会播放声音,这不是我的要求。需要与动画一起播放声音。
您需要为动画添加监听器。
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
mp.start();
}
@Override
public void onAnimationEnd(Animation animation) {
mp.stop();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
请为您的动画对象设置动画侦听器
animation.setAnimationListener(new AnimationListener()
{
@Override
public void onAnimationStart(Animation animation)
{
}
@Override
public void onAnimationRepeat(Animation animation)
{
}
@Override
public void onAnimationEnd(Animation animation)
{
if (m_player != null && m_player.isPlaying())
{
m_player.stop();
m_player.release();
m_player = null;
}
}
});