×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Question n8 (symbian belle) python problem

    I used 5800 and now I am attempting N8 with symbian belle.
    I have a my own python app related to play mp3 sound file. It worked very well in 5800 but it doesn't in N8. Certainly I installed python runtime 2.0.0 and python shell script 2.0.0 which I already had for 5800.

    First, I want know if there is a new version of PyS60 for symbian^3. I couldn't find it.

    If not, I want to know how to revise the python code for symbian^3 (for belle)
    The app is based on the code example (PyMPlayer.py) and it doesn't work with python script shell 2.0.0 in N8. It worked well with shell script 2.0.0 in 5800.

    What code should be revised for symbian^3? The code can't play mp3 file.

    please help!!!!! thanks in advance.

    shelbypapa@naver.com

    Code:
    '''
    # Symbian Foundation Example Code
    #
    # This software is in the public domain. No copyright is claimed, and you
    # may use it for any purpose without license from the Symbian Foundation.
    # No warranty for any purpose is expressed or implied by the authors or
    # the Symbian Foundation.
    '''
    import appuifw, e32, audio, graphics, os, sysinfo, operator
    from key_codes import *
    
    app_lock = e32.Ao_lock()
    def quit():
      player = None
      player.s.stop()
      player.s.close()
      player.timer.cancel()
    #  delete player
      app_lock.signal()
    appuifw.app.exit_key_handler = quit
    
    class PyMPlayer:
      def __init__(self, path):
        #The path where the player will look for sound files
        self.path = path
        #A variable that keeps track of the current state of the player; 
        #None means no song is open, False means playing is paused, and True means a song is playing
        self.playing = None
        #We will use this when coming out of pause in order to know from what point the song should play
        self.pickup_time = 0
        #Create an image the size of the screen
        self.img = graphics.Image.new(sysinfo.display_pixels())
        #Instantiate a Canvas and set it as the application's body,
        #and bind the keys that control playback options
        self.canvas = appuifw.Canvas(redraw_callback=self.handle_redraw)
        self.canvas.bind(EKeyUpArrow, self.volume_up)
        self.canvas.bind(EKeyDownArrow, self.volume_down)
        self.canvas.bind(EKeySelect, self.play_pause)
        appuifw.app.body = self.canvas
        appuifw.app.menu = [(u"Pick song", self.select_song)]
        #Instantiate a timer that will be used for updating the info displayed on the screen
        self.timer = e32.Ao_timer()
      
      def handle_redraw(self, rect):
        self.canvas.blit(self.img)
      
      #This function finds all the sound files in a certain directory
      #and displays them as a list for the user to choose from
      def select_song(self):
        self.list_of_songs = []
        for self.i in os.listdir(self.path):
          #Check if the extension is that of a sound file and if it is, add the name to the list
          if self.i[-4:] in [".mp3", ".wav", ".wma"]:
            self.list_of_songs.append(unicode(self.i))
        #Ask the user which file they want to play, if there are any
        if len(self.list_of_songs) > 0:
          try:
            self.file_name = self.list_of_songs[appuifw.selection_list(self.list_of_songs)]
          except TypeError: #Occurs when the user cancels the selection
            pass
        else:
          appuifw.note(u"No appropriate sound files available", 'info')
      
      def volume_up(self):
        try:
          self.s.set_volume(self.s.current_volume() + 1)
        except:
          pass
      
      def volume_down(self):
        try:
          self.s.set_volume(self.s.current_volume() - 1)
        except:
          pass
      
      #Here we handle opening a song for the first time and playing/pausing it
      def play_pause(self):
        if self.playing == False:
          self.s.set_position(self.pickup_time)
          self.playing = True
          self.s.play()
          self.show_info()
        elif self.playing == True:
          self.pickup_time = self.s.current_position()
          self.playing = False
          self.s.stop()
          self.timer.cancel()
        if self.playing == None:
          try: #If play is used before a song is selected, an error occurs
            self.s = audio.Sound.open(self.path + "\\" + self.file_name)
            appuifw.app.menu = [(u"Stop", self.stop)]
            self.playing = True
            self.s.play()
            self.show_info()
          except:
            pass
      
      #This function takes care of stopping playback
      def stop(self):
        appuifw.app.menu = [(u"Pick song", self.select_song)]
        self.s.stop()
        self.s.close()
        self.playing = None
        self.timer.cancel()
      
      #A function that establishes and displays elapsed time
      #and the duration of the song as well as the name of the file
      def show_info(self):
        #Calculate the values
    #   self.min1, self.sec1 = divmod((self.s.current_position() / 1000000), 60)
    #   self.min2, self.sec2 = divmod((self.s.duration() / 1000000), 60)
        self.min1, self.sec1 = mod((self.s.current_position() / 1000000), 60)
        self.min2, self.sec2 = mod((self.s.duration() / 1000000), 60)
        #Give the values the standard format mm:ss
        if self.min1<10:
          self.info = u"0" + unicode(self.min1)
        else:
          self.info = unicode(self.min1)
        self.info += u":"
        if self.sec1<10:
          self.info += u"0" + unicode(self.sec1)
        else:
          self.info += unicode(self.sec1)
        self.info += u" - "
        if self.min2<10:
          self.info += u"0" + unicode(self.min2)
        else:
          self.info += unicode(self.min2)
        self.info += u":"
        if self.sec2<10:
          self.info += u"0" + unicode(self.sec2)
        else:
          self.info += unicode(self.sec2)
        #Clear the image so things don't overlap
        self.img.clear()
        #Calculate where to display the info so that it's in the center of the screen
        self.text_size = self.img.measure_text(self.file_name, font='title')[0]
        self.text_width = self.text_size[2] - self.text_size[0]
        self.text_height = self.text_size[3] - self.text_size[1]
        self.text_x = (sysinfo.display_pixels()[0] / 2) - (self.text_width / 2)
        self.text_y = (sysinfo.display_pixels()[1] / 2) - self.text_height
        self.img.text((self.text_x, self.text_y), self.file_name, font='title')
        self.text_size = self.img.measure_text(self.info, font='title')[0]
        self.text_width = self.text_size[2] - self.text_size[0]
        self.text_height = self.text_size[3] - self.text_size[1]
        self.text_x = (sysinfo.display_pixels()[0] / 2) - (self.text_width / 2)
        self.text_y = (sysinfo.display_pixels()[1] / 2) - self.text_height
        self.img.text((self.text_x, self.text_y + self.text_height), self.info, font='title')
        self.handle_redraw(())
        #Update the info every second
        self.timer.after(1, self.show_info)
      
      #The class' destructor; here we close the currently open sound file, if any
      def __del__(self):
        try:
          self.s.stop()
          self.s.close()
        except:
          pass
    
    #Create an instance of the player, passing the path where the sound files are as an argument
    player = PyMPlayer(u"E:\\Study")
    
    app_lock.wait()
    Last edited by justhani07; 2012-09-19 at 00:45.

  2. #2
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: n8 (symbian belle) python problem

    Hi

    the latest release pys60 was February 10, 2010 -- there is no pys60 run-time for Symbian^3.

  3. #3
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Unhappy Re: n8 (symbian belle) python problem

    Thanks.
    I already have psy60 2.0.0 release.
    Some python apps are working well, but, sadly, you mean I cannot solve my problem.

    Aren't there anybody who can help me??? Please !!!!

  4. #4
    Registered User
    Join Date
    Feb 2005
    Location
    Belgium (Europe)
    Posts
    1,352

    Re: n8 (symbian belle) python problem

    hello,
    If you want to discover the problem give us the error message after launching this script.
    Thanks
    Cyke64
    pys60 1.4.5 and 2.0.0, pygame, PyS60 CE on E90 and 5800 !

    Find my pys60 extension modules on cyke64.googlepages.com

  5. #5
    Registered User
    Join Date
    Feb 2010
    Posts
    8

    Re: n8 (symbian belle) python problem

    Hi,
    thanks, but I am so sorry I resolved problem of PyMPlayer.py made by my mistake while testing the pycode.
    I changed function of divmod(...) to mod(...) so it made a NameError as follows.
    By returning divmod(...), it works well.

    Code:
    Traceback (most recent call last):
         File : e:\python\PyMPlayer.py" line 77, in play_pause
             self.show_info()
         File : e:\python\PyMPlayer.py" line 107, in show_info
             self.min1, self.sec1 = mod(self.s.current_position()/1000000, 60)
    NameError: global name 'mod' is not found
    By the way, can I ask one more question as you have many extension modules in your google?
    I would like to get a long tab function to recognize long press in touch screen of symbian^3 or s60v5 phones.
    Unfortunately, I didn't find the extension module including long tab function even in your google.
    If any, let me know where...
    Thank you a lot....
    Last edited by justhani07; 2012-09-24 at 03:25.

Similar Threads

  1. problem with answering call on symbian belle
    By prashantchougule.cs in forum Symbian
    Replies: 13
    Last Post: 2012-05-16, 11:26
  2. Symbian Belle receive messages and CAknWaitDialog problem
    By asat232 in forum Symbian User Interface
    Replies: 7
    Last Post: 2012-04-26, 11:27
  3. problem with nokia 701 symbian belle ...
    By super_rider in forum General Development Questions
    Replies: 1
    Last Post: 2011-11-04, 17:45

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×