zoukankan      html  css  js  c++  java
  • 如何让MediaPlayer静音

        最近要实现一个功能,类似于书籍浏览,自动翻页,在浏览页面的同时还带有声音(背景音乐),有一个按钮,点击则关闭声音,再点击就恢复原来的声音。查找完MediaPlayer的API后,发现貌似没有这个方法,实现静音功能。不过这里有个方法,可以达到这个效果。用的是AudiaManager这个类,实现的代码如下:

    AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);

    btnSound.setOnClickListener(new OnClickListener() {
     
                @Override
                public void onClick(View v) {
                    if (SoundEnabled) {
                        audioManager.setStreamMute(AudioManager.STREAM_MUSIC , true);
                    } else {
                        audioManager.setStreamMute(AudioManager.STREAM_MUSIC , false);
                    }
                    SoundEnabled = !SoundEnabled;
     
                }

    });

    文章推荐:   http://4225953-163-com.iteye.com/blog/663694

  • 相关阅读:
    Gym
    HDU-2680 Choose the best route 单向边+反向dijkstra
    Hdu1010Tempter of the Bone 深搜+剪枝
    CodeForces
    CodeForces
    Gym-101375C MaratonIME eats japanese food 初始化struct技巧
    Gym
    java was started but returned exit code =-805306369的处理方法
    启动myeclipse弹窗Please allow Subclipse team to receive anonymous usage statistics for this Eclipse intance
    eclipse包分层
  • 原文地址:https://www.cnblogs.com/yangzhenyu/p/2196207.html
Copyright © 2011-2022 走看看