~ubuntu-branches/ubuntu/wily/python-sfml/wily

« back to all changes in this revision

Viewing changes to examples/sound/sound.py

  • Committer: Package Import Robot
  • Author(s): James Cowgill
  • Date: 2013-12-09 17:50:52 UTC
  • mfrom: (1.1.3) (8.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131209175052-11v6drpb6g3yksst
Tags: 1.5.1.is.1.3+dfsg-1
* New upstream version 1.3 (from python-sfml.org)
  - This is a complete rewrite of the Python bindings for SFML2, and
    the new maintainer is using a different version numbering scheme.
* Added myself to the list of uploaders
* Change package priority from extra to optional
* Bumped standards version (to 3.9.5) and debhelper compat (to 9)
* Added Python 3 and documentation packages
* Improve package description for debug packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
# -*- coding: utf-8 -*-
 
3
#
 
4
# pySFML - Python bindings for SFML
 
5
# Copyright 2012-2013, Jonathan De Wachter <dewachter.jonathan@gmail.com>
 
6
#
 
7
# This software is released under the LGPLv3 license.
 
8
# You should have received a copy of the GNU Lesser General Public License
 
9
# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
10
 
 
11
import sfml as sf
 
12
 
 
13
def play_sound():
 
14
        # load a sound buffer from a wav file
 
15
        buffer = sf.SoundBuffer.from_file("data/canary.wav")
 
16
 
 
17
        # display sound informations
 
18
        print("canary.wav:")
 
19
        print("{0} seconds".format(buffer.duration))
 
20
        print("{0} samples / sec".format(buffer.sample_rate))
 
21
        print("{0} channels".format(buffer.channel_count))
 
22
 
 
23
        # create a sound instance and play it
 
24
        sound = sf.Sound(buffer)
 
25
        sound.play();
 
26
 
 
27
        # loop while the sound is playing
 
28
        while sound.status == sf.Sound.PLAYING:
 
29
                # leave some CPU time for other processes
 
30
                sf.sleep(sf.milliseconds(100))
 
31
 
 
32
def play_music():
 
33
        # load an ogg music file
 
34
        music = sf.Music.from_file("data/orchestral.ogg")
 
35
 
 
36
        # display music informations
 
37
        print("orchestral.ogg:")
 
38
        print("{0} seconds".format(music.duration))
 
39
        print("{0} samples / sec".format(music.sample_rate))
 
40
        print("{0} channels".format(music.channel_count))
 
41
 
 
42
        # play it
 
43
        music.play();
 
44
 
 
45
        # loop while the music is playing
 
46
        while music.status == sf.Music.PLAYING:
 
47
                # leave some CPU time for other processes
 
48
                sf.sleep(sf.milliseconds(100))
 
49
 
 
50
if __name__ == "__main__":
 
51
        play_sound()
 
52
        play_music()
 
53
 
 
54
        input("Press enter to exit...")