mnit simple : improved audio tests
[nit.git] / examples / mnit_simple / 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 var soundsp: nullable Sound
25 var soundmp: nullable Sound
26 var test_assets = false
27 var test_ressources = true
28
29 redef fun window_created
30 do
31 super
32 if test_assets then
33 soundsp = load_sound("testsound.ogg")
34 soundmp = load_music("xylofon.ogg")
35 end
36 if test_ressources then
37 soundsp = load_sound_from_res("testsound")
38 soundmp = load_music_from_res("xylofon")
39 end
40 default_mediaplayer.looping = true
41 soundmp.play
42 end
43
44 redef fun input( ie )
45 do
46 if ie isa PointerEvent and ie.depressed then
47 soundsp.play
48 end
49 return super
50 end
51 end