WEB开发网
开发学院手机开发Android 开发 Android 用AudioManager类控制音量 阅读

Android 用AudioManager类控制音量

 2010-07-05 00:03:00 来源:WEB开发网   
核心提示:package com.terry;import android.app.Activity;import android.media.AudioManager;import android.os.Bundle;import android.view.View;import android.view.View.OnCli

package com.terry;

import android.app.Activity;

import android.media.AudioManager;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.ImageButton;

import android.widget.ImageView;

import android.widget.ProgressBar;

public class AudioManagerActivity extends Activity {

//音量变量

private int volume=0;

//声音模式

private int mode;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

findview();

//通过getStreamVolume 获得当前音量大小

volume=viewHolder.audiomanage.getStreamVolume(AudioManager.STREAM_RING);

//把当前音量的值 设置给进度条

viewHolder.myProgressBar.setProgress(volume);

//得到当前的声音模式

mode=viewHolder.audiomanage.getRingerMode();

setImageState();

viewHolder.downButton=btnListener(viewHolder.downButton);

viewHolder.upButton=btnListener(viewHolder.upButton);

viewHolder.muteButton=btnListener(viewHolder.muteButton);

viewHolder.normalButton=btnListener(viewHolder.normalButton);

viewHolder.vibrateButton=btnListener(viewHolder.vibrateButton);

}

//找到控件

void findview(){

viewHolder.downButton=(ImageButton)findViewById(R.id.downButton);

viewHolder.upButton=(ImageButton)findViewById(R.id.upButton);

viewHolder.muteButton=(ImageButton)findViewById(R.id.muteButton);

viewHolder.normalButton=(ImageButton)findViewById(R.id.normalButton);

viewHolder.vibrateButton=(ImageButton)findViewById(R.id.vibrateButton);

viewHolder.myImageView=(ImageView)findViewById(R.id.myImage);

上一页  1 2 3 4 5 6  下一页

Tags:Android AudioManager 控制

编辑录入:coldstar [复制链接] [打 印]
赞助商链接