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(); } } }
安卓一首音乐的播放+图片旋转
最新推荐文章于 2021-05-26 08:32:25 发布