SlideShare une entreprise Scribd logo
1  sur  11
Develop on Android
Android Lab Test
www.AndroidLabTest.com
Youku
By Bruno Delb
www.weibo.com/brunodelb
i.youku.com/brunodelb | www.weibo.com/brunodelb | blog.delb.cn
http://i.youku.com/brunoparis
Weibo
Officialsite
Lesson : The sound, with SoundPool
The sound, with SoundPool
• In this lesson, you will learn to play sounds.
• For this, you will use the SoundPool.
The sound, with SoundPool
• Create a SoundPool with these parameters :
– the maximum number of streams,
– the type of stream (example : STREAM_MUSIC),
– the quality (not yet used).
SoundPool soundPool;
soundPool = new SoundPool (
2, // max streams
AudioManager.STREAM_MUSIC, // stream type
100 // quality (not used)
);
The sound, with SoundPool
• Load the sounds with the method load() with the parameters :
– the context,
– the resource id,
– the priority.
• As result, you get an id (soundId).
soundId = soundPool.load (
this, // context
R.raw.audiofile, // resource id
0 // priority
);
The sound, with SoundPool
• Play each sound with the method play() with these parameters :
– the sound id,
– the left and right volumes,
– the priority,
– the status if the sound should be played in loop or not,
– the speed playback.
soundPool.play (
soundId, // sound id
1f, // left volume (0.0-1.0)
1f, // right volume (0.0-1.0)
0, // priority (0 = the lowest)
0, // loop (0 = no, -1 = yes)
1f // rate (0.5-2.0)
);
Resources
• An audio file audiofile (any extension) should be present in
the directory resraw of the project.
Layout main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Play"
android:id="@+id/btnPlay" />
</LinearLayout>
File Main.javapublic class Main extends Activity {
SoundPool soundPool;
int soundId;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnPlay = (Button)this.findViewById(R.id.btnPlay);
btnPlay.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
soundPool.play (
soundId, // sound id
1f, // left volume (0.0 à 1.0)
1f, // right volume (0.0 à 1.0)
0, // priority
0, // loop
1f // rate (de 0.5 à 2.0)
);
}
});
File Main.java
soundPool = new SoundPool (
2, // max streams
AudioManager.STREAM_MUSIC, // stream type
100 // quality (not used)
);
soundId = soundPool.load (
this, // context
R.raw.audiofile, // resource id
1 // priority
);
}
}
Test on your mobile
Media_SoundPool
Follow me on my channel PengYooTV …
On my Youku channel
http://i.youku.com/brunoparis
Who am I ?
Bruno Delb (www.delb.cn),
Author of the first french book of development of Java mobile application (2002),
Consultant, project manager and developer of social & mobile applications,
let’s talk about your needs ...
And on Weibo :
http://www.weibo.com/brunodelb

Contenu connexe

Tendances (6)

Deep Learning with Audio Signals: Prepare, Process, Design, Expect
Deep Learning with Audio Signals: Prepare, Process, Design, ExpectDeep Learning with Audio Signals: Prepare, Process, Design, Expect
Deep Learning with Audio Signals: Prepare, Process, Design, Expect
 
Business of Music - Class 6
Business of Music - Class 6Business of Music - Class 6
Business of Music - Class 6
 
Deep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problemDeep dive into Android’s audio latency problem
Deep dive into Android’s audio latency problem
 
Conditional generative model for audio
Conditional generative model for audioConditional generative model for audio
Conditional generative model for audio
 
Rhl sound generation_1
Rhl sound generation_1Rhl sound generation_1
Rhl sound generation_1
 
Alpan Aytekin-Game Audio Essentials
Alpan Aytekin-Game Audio EssentialsAlpan Aytekin-Game Audio Essentials
Alpan Aytekin-Game Audio Essentials
 

En vedette (8)

My Preschool Years
My Preschool YearsMy Preschool Years
My Preschool Years
 
Android Lab Test : Les vues, Gallery (français)
Android Lab Test : Les vues, Gallery (français)Android Lab Test : Les vues, Gallery (français)
Android Lab Test : Les vues, Gallery (français)
 
Android Lab Test : L'installation d'une application en Java (français)
Android Lab Test : L'installation d'une application en Java (français)Android Lab Test : L'installation d'une application en Java (français)
Android Lab Test : L'installation d'une application en Java (français)
 
Leervoorkeuren en denkgewoonten
Leervoorkeuren en denkgewoontenLeervoorkeuren en denkgewoonten
Leervoorkeuren en denkgewoonten
 
Le langage Lisp
Le langage LispLe langage Lisp
Le langage Lisp
 
Programming For Special Needs My Presentation
Programming For Special Needs My PresentationProgramming For Special Needs My Presentation
Programming For Special Needs My Presentation
 
Android Lab Test : Les appels téléphoniques (français)
Android Lab Test : Les appels téléphoniques (français)Android Lab Test : Les appels téléphoniques (français)
Android Lab Test : Les appels téléphoniques (français)
 
Placed Students
Placed StudentsPlaced Students
Placed Students
 

Similaire à Android Lab Test : Managing sounds with SoundPool (english)

Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
Andreas Jung
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
Romain Guy
 
Ig2 task 1 work sheet newi9979
Ig2 task 1 work sheet newi9979Ig2 task 1 work sheet newi9979
Ig2 task 1 work sheet newi9979
CallumDrakeCPFC
 
Ian definitions 3rd try 2
Ian definitions 3rd try 2Ian definitions 3rd try 2
Ian definitions 3rd try 2
thomasmcd6
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
copelandadam
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
copelandadam
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
copelandadam
 

Similaire à Android Lab Test : Managing sounds with SoundPool (english) (20)

10.1. Android Audio
10.1. Android Audio10.1. Android Audio
10.1. Android Audio
 
Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)Get On The Audiobus (CocoaConf Atlanta, November 2013)
Get On The Audiobus (CocoaConf Atlanta, November 2013)
 
Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)Get On The Audiobus (CocoaConf Boston, October 2013)
Get On The Audiobus (CocoaConf Boston, October 2013)
 
Building Android games using LibGDX
Building Android games using LibGDXBuilding Android games using LibGDX
Building Android games using LibGDX
 
Intro to Building Android Games using libGDX
Intro to Building Android Games using libGDXIntro to Building Android Games using libGDX
Intro to Building Android Games using libGDX
 
Android media-chapter 23
Android media-chapter 23Android media-chapter 23
Android media-chapter 23
 
Basic Android
Basic AndroidBasic Android
Basic Android
 
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
 
Frequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last timeFrequently asked questions answered frequently - but now for the last time
Frequently asked questions answered frequently - but now for the last time
 
Google I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb HighlightsGoogle I/O 2011, Android Honeycomb Highlights
Google I/O 2011, Android Honeycomb Highlights
 
Android Audio & OpenSL
Android Audio & OpenSLAndroid Audio & OpenSL
Android Audio & OpenSL
 
Python 101
Python 101Python 101
Python 101
 
Scaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approachScaling python webapps from 0 to 50 million users - A top-down approach
Scaling python webapps from 0 to 50 million users - A top-down approach
 
IG2 Task 1 Work Sheet
IG2 Task 1 Work SheetIG2 Task 1 Work Sheet
IG2 Task 1 Work Sheet
 
Ig2 task 1 work sheet newi9979
Ig2 task 1 work sheet newi9979Ig2 task 1 work sheet newi9979
Ig2 task 1 work sheet newi9979
 
Ian definitions 3rd try 2
Ian definitions 3rd try 2Ian definitions 3rd try 2
Ian definitions 3rd try 2
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
 
Adam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheetAdam copeland ig2 task 1 work sheet
Adam copeland ig2 task 1 work sheet
 

Plus de Bruno Delb

Plus de Bruno Delb (20)

Introduction to Swift (tutorial)
Introduction to Swift (tutorial)Introduction to Swift (tutorial)
Introduction to Swift (tutorial)
 
Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)Android Lab Test : Storage of data with SharedPreferences (english)
Android Lab Test : Storage of data with SharedPreferences (english)
 
Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)Android Lab Test : Using the sensor gyroscope (english)
Android Lab Test : Using the sensor gyroscope (english)
 
Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)Android Lab Test : Using the network with HTTP (english)
Android Lab Test : Using the network with HTTP (english)
 
Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)Android Lab Test : Using the text-to-speech (english)
Android Lab Test : Using the text-to-speech (english)
 
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
 
Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)Android Lab Test : Creating a menu dynamically (english)
Android Lab Test : Creating a menu dynamically (english)
 
Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)Android Lab Test : Creating a dialog Yes/No (english)
Android Lab Test : Creating a dialog Yes/No (english)
 
Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)Android Lab Test : The styles of views (english)
Android Lab Test : The styles of views (english)
 
Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)Android Lab Test : Creating a menu context (english)
Android Lab Test : Creating a menu context (english)
 
Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)Android Lab Test : Using the camera preview (english)
Android Lab Test : Using the camera preview (english)
 
Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)Android Lab Test : The views, the Gallery (english)
Android Lab Test : The views, the Gallery (english)
 
Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)Android Lab Test : Using the WIFI (english)
Android Lab Test : Using the WIFI (english)
 
Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)Android Lab Test : Managing the telephone calls (english)
Android Lab Test : Managing the telephone calls (english)
 
Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)Android Lab Test : Reading the SMS-inbox (english)
Android Lab Test : Reading the SMS-inbox (english)
 
Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)Android Lab Test : Installation of application in Java (english)
Android Lab Test : Installation of application in Java (english)
 
Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)Android Lab Test : Ecrire un texte sur le canevas (français)
Android Lab Test : Ecrire un texte sur le canevas (français)
 
Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)Android Lab Test : La connectivité réseau avec HTTP (français)
Android Lab Test : La connectivité réseau avec HTTP (français)
 
Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)Android Lab Test : Le capteur gyroscope (français)
Android Lab Test : Le capteur gyroscope (français)
 
Android Lab Test : Les threads (français)
Android Lab Test : Les threads (français)Android Lab Test : Les threads (français)
Android Lab Test : Les threads (français)
 

Dernier

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Dernier (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 

Android Lab Test : Managing sounds with SoundPool (english)

  • 1. Develop on Android Android Lab Test www.AndroidLabTest.com Youku By Bruno Delb www.weibo.com/brunodelb i.youku.com/brunodelb | www.weibo.com/brunodelb | blog.delb.cn http://i.youku.com/brunoparis Weibo Officialsite Lesson : The sound, with SoundPool
  • 2. The sound, with SoundPool • In this lesson, you will learn to play sounds. • For this, you will use the SoundPool.
  • 3. The sound, with SoundPool • Create a SoundPool with these parameters : – the maximum number of streams, – the type of stream (example : STREAM_MUSIC), – the quality (not yet used). SoundPool soundPool; soundPool = new SoundPool ( 2, // max streams AudioManager.STREAM_MUSIC, // stream type 100 // quality (not used) );
  • 4. The sound, with SoundPool • Load the sounds with the method load() with the parameters : – the context, – the resource id, – the priority. • As result, you get an id (soundId). soundId = soundPool.load ( this, // context R.raw.audiofile, // resource id 0 // priority );
  • 5. The sound, with SoundPool • Play each sound with the method play() with these parameters : – the sound id, – the left and right volumes, – the priority, – the status if the sound should be played in loop or not, – the speed playback. soundPool.play ( soundId, // sound id 1f, // left volume (0.0-1.0) 1f, // right volume (0.0-1.0) 0, // priority (0 = the lowest) 0, // loop (0 = no, -1 = yes) 1f // rate (0.5-2.0) );
  • 6. Resources • An audio file audiofile (any extension) should be present in the directory resraw of the project.
  • 7. Layout main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Play" android:id="@+id/btnPlay" /> </LinearLayout>
  • 8. File Main.javapublic class Main extends Activity { SoundPool soundPool; int soundId; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button btnPlay = (Button)this.findViewById(R.id.btnPlay); btnPlay.setOnClickListener(new OnClickListener() { public void onClick(View v) { soundPool.play ( soundId, // sound id 1f, // left volume (0.0 à 1.0) 1f, // right volume (0.0 à 1.0) 0, // priority 0, // loop 1f // rate (de 0.5 à 2.0) ); } });
  • 9. File Main.java soundPool = new SoundPool ( 2, // max streams AudioManager.STREAM_MUSIC, // stream type 100 // quality (not used) ); soundId = soundPool.load ( this, // context R.raw.audiofile, // resource id 1 // priority ); } }
  • 10. Test on your mobile Media_SoundPool
  • 11. Follow me on my channel PengYooTV … On my Youku channel http://i.youku.com/brunoparis Who am I ? Bruno Delb (www.delb.cn), Author of the first french book of development of Java mobile application (2002), Consultant, project manager and developer of social & mobile applications, let’s talk about your needs ... And on Weibo : http://www.weibo.com/brunodelb