女人被狂躁到高潮视频免费无遮挡,内射人妻骚骚骚,免费人成小说在线观看网站,九九影院午夜理论片少妇,免费av永久免费网址

當(dāng)前位置:首頁 > > 充電吧
[導(dǎo)讀]1.SoundPool 簡介 開發(fā)Android軟件中我們可能經(jīng)常需播放多媒體聲音文件,一般使用MediaPlayer類 但該類占用資源較多,對于游戲等應(yīng)用可能不是很適合,SoundPool類在SDK

1.SoundPool 簡介 開發(fā)Android軟件中我們可能經(jīng)常需播放多媒體聲音文件,一般使用MediaPlayer類 但該類占用資源較多,對于游戲等應(yīng)用可能不是很適合,SoundPool類在SDK 的android.media.SoundPool,顧名思義是聲音池的意思。主要播放一些較短的聲音 片段,可以從程序的資源或文件系統(tǒng)加載,相對于MediaPlayer類可以做到使用較少 的CPU資源和較短的反應(yīng)延遲。 ?????SoundPool和其他聲音播放類相比,其特點(diǎn)是可以自行設(shè)置聲音的 品質(zhì)、音量、播放比率等參等。并且它可以同時管理多個音頻流,每個 流都有獨(dú)自的ID,對某個音頻流的管理都是通過ID進(jìn)行的。

2 使用方法 SoundPool基本使用方法:

??????????????1. 創(chuàng)建一個SoundPool?
? ?? ?? ?? ?? ???創(chuàng)建一個SoundPool對象:new SoundPool(int maxStreams, int streamType, int srcQuality);

??????????????  public SoundPool(int maxStream, int streamType, int srcQuality)?
??????????????  maxStream —— 同時播放的流的最大數(shù)量?
????????????????? streamType —— 流的類型,一般為STREAM_MUSIC(具體在AudioManager類中列出)?
?????????? ? ?? ? srcQuality —— 采樣率轉(zhuǎn)化質(zhì)量,當(dāng)前無效果,使用0作為默認(rèn)值?
?????????? ? ? ?? eg.?
  ?????????? ? ? ?? SoundPool soundPool = new SoundPool(3, AudioManager.STREAM_MUSIC, 0);

??????????????? ? ? ?? 創(chuàng)建了一個最多支持3個流同時播放的,類型標(biāo)記為音樂的SoundPool。
  ? ?? ???2、 從資源或者文件載入音頻流: load(Context context, int resId, int priority);

??????????????????? soundpool的加載:?
??? ? ? ? ? ? ? ? ? ?? int? load(Context context, int resId, int priority)? //從APK資源載入?
? ? ? ? ? ? ? ? ? ? ?? int? load(FileDescriptor fd, long offset, long length, int priority)? //從FileDescriptor對象載入?
? ? ? ? ? ? ? ? ? ? ?? int? load(AssetFileDescriptor afd, int priority)? //從Asset對象載入?
?????????????????????? int? load(String path, int priority)? //從完整文件路徑名載入?
????????????????????????????????? 最后一個參數(shù)為優(yōu)先級。

???????????? ? ? ? ? ? ? 一般把多個聲音放到HashMap中去,比如?
?????????????????????? ? soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);?
??????????????????? ? ?? soundPoolMap = new HashMap

????????? ? ? ? ?? ? play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate) ,

??? ? ? ? ? ? ? ? ? ?? 其中l(wèi)eftVolume和rightVolume表示左右音量,

??????????????????????????? priority表示優(yōu)先級,

??????????????????????????? loop表示循環(huán)次數(shù),

?????????????????????????? rate表示速率,如? //速率最低0.5最高為2,1代表正常速度?
??????????????????? sp.play(soundId, 1, 1, 0, 0, 1);?
? ? ? ? ? ? ? ? ? ? 而停止則可以使用 pause(int streamID) 方法,這里的streamID和soundID均在構(gòu)造SoundPool類的

??????????????????? 第一個參數(shù)中指明了總數(shù)量,而id從0開始。


3. soundpool一個小應(yīng)用 布局 xml 代碼:




java 代碼:

package?com.example.android_sample_3_1;

import?java.util.HashMap;

import?android.media.AudioManager;
import?android.media.SoundPool;
import?android.os.Bundle;
import?android.provider.MediaStore.Audio;
import?android.app.Activity;
import?android.view.Menu;
import?android.view.View;
import?android.widget.Button;
import?android.widget.Toast;

public?class?MainActivity?extends?Activity?{

	SoundPool?sp;
	HashMapspMap;
	Button?b1;
	Button?b1Pause;
	Button?b2;
	Button?b2Pause;
	@Override
	protected?void?onCreate(Bundle?savedInstanceState)?{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		initSoundPool();
		b1?=?(Button)?findViewById(R.id.button1);
		b1Pause?=?(Button)?findViewById(R.id.button3);
		b2?=?(Button)?findViewById(R.id.button2);
		b2Pause?=?(Button)?findViewById(R.id.button4);
		
		b1.setOnClickListener(new?View.OnClickListener()?{
			
			@Override
			public?void?onClick(View?v)?{
				palySound(1,?1);
				Toast.makeText(MainActivity.this,?"播放音效1",?Toast.LENGTH_SHORT).show();
			}
		});
		b1Pause.setOnClickListener(new?View.OnClickListener()?{
			
			@Override
			public?void?onClick(View?v)?{
				sp.pause(spMap.get(1));
				Toast.makeText(MainActivity.this,?"暫停音效1",?Toast.LENGTH_SHORT).show();
			}
		});
		b2.setOnClickListener(new?View.OnClickListener()?{
			
			@Override
			public?void?onClick(View?v)?{
				palySound(2,?1);
				Toast.makeText(MainActivity.this,?"播放音效2",?Toast.LENGTH_SHORT).show();
			}
		});
		b2Pause.setOnClickListener(new?View.OnClickListener()?{
			
			@Override
			public?void?onClick(View?v)?{
				sp.pause(spMap.get(2));
				Toast.makeText(MainActivity.this,?"暫停音效2",?Toast.LENGTH_SHORT).show();
			}
		});
	}
	private?void?palySound(int?sound,?int?number)?{
		AudioManager?am?=?(AudioManager)?this.getSystemService(this.AUDIO_SERVICE);
		float?audioMaxVolumn?=?am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
		float?audioCurrentVolumn?=?am.getStreamVolume(AudioManager.STREAM_MUSIC);
		float?volumnRatio?=?audioCurrentVolumn?/?audioMaxVolumn;
		sp.play(spMap.get(sound),?volumnRatio,?volumnRatio,?1,?number,?1);
		
	}
	private?void?initSoundPool()?{
		sp?=?new?SoundPool(5,?AudioManager.STREAM_MUSIC,?0);
		spMap?=?new?HashMap();
		spMap.put(1,?sp.load(this,?R.raw.attack02,?1));
		spMap.put(2,?sp.load(this,?R.raw.attack14,?1));
	}

	@Override
	public?boolean?onCreateOptionsMenu(Menu?menu)?{
		//?Inflate?the?menu;?this?adds?items?to?the?action?bar?if?it?is?present.
		getMenuInflater().inflate(R.menu.main,?menu);
		return?true;
	}

}





本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

其他電腦(比如安卓手機(jī)/平板電腦)的屏幕壞了,你可能想在安排維修之前緊急訪問一些東西。你可以使用android的USB OTG功能(是的,幾乎每個android都支持這個功能,你可以將鼠標(biāo)和鍵盤連接到它)。

關(guān)鍵字: USB 鼠標(biāo) Android 樹莓派

Google 宣布與中國 AR 科技公司 XREAL 達(dá)成深度戰(zhàn)略合作,聯(lián)合推出全球首款專為 Android XR 平臺打造的旗艦級 AR 眼鏡 Project Aura。

關(guān)鍵字: Google XREAL Android XR眼鏡 AR

繼停止維護(hù)AOSP開源項(xiàng)目后,谷歌母公司Alphabet近日被曝在其安卓系統(tǒng)(Android)、Pixel手機(jī)以及Chrome瀏覽器等部門裁員數(shù)百人。這一舉措引發(fā)了業(yè)界的廣泛關(guān)注,也引發(fā)了對谷歌未來業(yè)務(wù)布局的諸多猜測。

關(guān)鍵字: 谷歌 AOSP Android 裁員

在本教程中,我們將使用Capacitor 6、Angular和TypeScript構(gòu)建一個Android應(yīng)用程序,該應(yīng)用程序通過串行端口連接到BleuIO USB加密狗。該應(yīng)用程序允許用戶直接從Android設(shè)備發(fā)送和接...

關(guān)鍵字: Android USB 電容器 BLE設(shè)備

早前媒體報道谷歌將停止維護(hù)Android開源項(xiàng)目(AOSP),將Android開發(fā)全面轉(zhuǎn)向內(nèi)部閉源分支,目前這一消息已經(jīng)得到谷歌官方確認(rèn)。

關(guān)鍵字: 谷歌 Android 開源

本項(xiàng)目演示了如何通過OTG (on - go) USB在Android設(shè)備上使用BleuIO USB加密狗作為串行端口。使用電容器6和@adeunis/電容器-串行插件,我們建立串行連接,發(fā)送AT命令,并實(shí)時讀取響應(yīng)。該...

關(guān)鍵字: 電容器 Android 傳感器 微控制器 嵌入式系統(tǒng)

在Linux操作系統(tǒng)中,Android Debug Bridge(ADB)是一個功能強(qiáng)大的命令行工具,它允許開發(fā)者在計算機(jī)和Android設(shè)備之間建立通信,從而進(jìn)行調(diào)試、管理、安裝應(yīng)用等操作。本文將詳細(xì)介紹在Linux系...

關(guān)鍵字: Linux系統(tǒng) Android Debug ADB

隨著Android操作系統(tǒng)的進(jìn)步,智能手機(jī)的使用日益增加。隨后,有報道稱,惡意個人和黑客利用 Android 提供的漏洞來訪問用戶珍視的數(shù)據(jù)。例如,此類威脅包括 2021 年針對 Android 設(shè)備發(fā)布的 Flubot...

關(guān)鍵字: Android 惡意軟件

在本教程中,我們將構(gòu)建超出電子領(lǐng)域的東西。作為一名電子工程師,我們大多數(shù)人都想為我們的物聯(lián)網(wǎng)應(yīng)用程序構(gòu)建一些用戶界面,在大多數(shù)情況下,Android應(yīng)用程序?qū)⑹怯脩襞c我們的物聯(lián)網(wǎng)設(shè)備交互的正確選擇。所以,如果你想為你的物...

關(guān)鍵字: 物聯(lián)網(wǎng) Android
關(guān)閉