contrib/mnit_test: improve documentation of `test_audio`
[nit.git] / contrib / mnit_test / src / test_audio.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Test for the audio module of App.nit framework
18 module test_audio
19
20 import simple_android
21 import android::audio
22
23 redef class App
24 # Sound
25 var soundsp: Sound
26
27 # Music
28 var soundmp: Music
29
30 # Sound
31 var easy_soundsp = new Sound("testsound")
32
33 # Music
34 var easy_soundmp = new Music("xylofon")
35
36 # Read sounds from the assets folder?
37 var test_assets = false
38
39 # Read sounds from the resources folder?
40 var test_ressources = true
41
42 # Test the automatic way with `PlayableAudio::load`?
43 var test_easy_sounds = false
44
45 redef fun on_create
46 do
47 super
48 default_mediaplayer.looping = true
49 if test_assets then
50 soundsp = load_sound("testsound.og")
51 soundmp = load_music("xylofon.og")
52 soundmp.play
53 end
54 if test_ressources then
55 soundsp = load_sound_from_res("testsound")
56 soundmp = load_music_from_res("xylofon")
57 soundmp.play
58 end
59 if test_easy_sounds then
60 easy_soundsp.load
61 easy_soundmp.load
62 easy_soundmp.play
63 end
64 end
65
66 redef fun input( ie )
67 do
68 if ie isa PointerEvent and ie.depressed then
69 if test_assets or test_ressources then
70 soundsp.play
71 else if test_easy_sounds then
72 easy_soundsp.play
73 end
74 end
75 return super
76 end
77 end