安卓一首音乐的播放+图片旋转

package bawei.com.jinretoutian.childFrangment;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.ImageView;

import java.io.IOException;

import bawei.com.jinretoutian.R;

/**
 * Created by lenovo on 2017/11/21.
 */

public class child5 extends Fragment {

    private Button bu1;
    private Button bu2;
    private Button bu3;
    private MediaPlayer my;
    private ImageView img;
    private RotateAnimation animation;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.ff5, container, false);


        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        my = new MediaPlayer();
        animation = new RotateAnimation(0, 360);
        bu1 = (Button) view.findViewById(R.id.bu1);

        bu1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                indatae();//开始旋转

                my.reset();//音乐重置
                paly();//音乐播放
            }
        });


        bu2 = (Button)view.findViewById(R.id.bu2);

        bu2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                animation.cancel();//暂停图片
                my.pause();//音乐暂停
            }
        });



        bu3 = (Button)view.findViewById(R.id.bu3);

        img = (ImageView)view.findViewById(R.id.img);






    }

    private void indatae() {

        animation.setDuration(3000);//设定转一圈的时间
        animation.setRepeatCount(Animation.INFINITE);//设定无限循环
        animation.setRepeatMode(Animation.RESTART);//
        img.startAnimation(animation);
    }

    public void paly(){
        String path = Environment.getExternalStorageDirectory()+"/ycla.mp3";

        try {
            my.setDataSource(path);
            my.prepare();
            my.start();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值