android studio闪光灯结合音乐播放源码

MainActivity:package com.example.xbg.flashlight;import android.content.Context; importandroid.hardware.camera2.CameraAccessException; importandroid.hardware.camera2.CameraManager; importandroid...
摘要由CSDN通过智能技术生成

MainActivity:

  1. package com.example.xbg.flashlight;

    import android.content.Context; import
    android.hardware.camera2.CameraAccessException; import
    android.hardware.camera2.CameraManager; import
    android.media.MediaPlayer; import android.os.Build; import
    android.support.annotation.RequiresApi; import
    android.support.v7.app.AppCompatActivity; import android.os.Bundle;
    import android.view.View; import android.widget.Button;

    public class MainActivity extends AppCompatActivity {
    private CameraManager cameraManager;//定义
    private String cameraId;
    private Button button;
    private boolean islight=false;
    private Button openFlicker;
    private Button closeFlicker;
    private Boolean isShanshuo;
    private MediaPlayer player;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final MediaPlayer mediaPlayer=MediaPlayer.create(this,R.raw.shape);//存储音乐资源
        Button btn_play=(Button) findViewById(R.id.button4);
        Button btn_stop=(Button) findViewById(R.id.button5);
        button=(Button) this.findViewById(R.id.button);
        openFlicker=(Button) this.findViewById(R.id.button2) ;
        closeFlicker=(Button) this.findViewById(R.id.button3);
    
        cameraManager=(CameraManager) getSystemService(Context.CAMERA_SERVICE);//获取canera设备
        try{
            switch (cameraId = cameraManager.getCameraIdList()[0]) {
            }
        } catch (CameraAccessException e){
            e.printStackTrace();
        }
    
        btn_play.setOnClickListener(new View.OnClickListener(){
            @Override
       
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值