18 Replies Latest reply on Dec 14, 2014 3:01 PM by Marcus Atkins

    Alert.play_file not working

      Hi all,

       

      I'm trying to implement a function that will play an mp3 and a wav file

      I've placed 2 files in the public folder of my application:

      1. Bluesy_guitar.mp3

      2. Space.wav

       

      Here is the code I have implemented in my alert_controller.rb file

       

        def play_file1
          @title = "play_file1"
          Alert.play_file "Bluesy_guitar.mp3"
          render :action => :index
        end
        
        def play_file2
          @title = "play_file2"
          Alert.play_file "Space.wav"
          render :action => :index
        end
      
      

       

       

      Everytime I try running these methods, I keep getting this error in the log.txt file

       

      RhoFileApi| Opening file from file system: /data/data/com.rhomobile.pimalerts/rhodata/apps/Bluesy_guitar.mp3

       

      RhoFileApi| Can not open file descriptor: /data/data/com.rhomobile.pimalerts/rhodata/apps/Bluesy_guitar.mp3: open failed: ENOENT (No such file or directory)

       

      Alert| Call of "playFile" failed: null

       

       

      Not sure what's going wrong here.

       

      I've tried putting

      Alert.play_file "/public/Bluesy_guitar.mp3"
      

       

      I've tried putting the entire path from the root to the file, but nothing's working.

      I'm not sure where this path name came from either : /data/data/com.rhomobile.pimalerts/rhodata/apps/

       

      I'd appreciate any kind of help.

       

      Thanks,

      Ariana

        • Re: Alert.play_file not working

          http://docs.rhomobile.com/rhodes/device-caps#file-system-access

           

           

           

          use get_public_folder()

           

           

           

          File.join(Rho::RhoApplication::get_public_folder(), 'Bluesy_guitar.mp3')

            • Re: Alert.play_file not working

              So what I did was replace

              Alert.play_file "/public/Bluesy_guitar.mp3"

              with

              Alert.play_file File.join(Rho::RhoApplication::get_public_folder(), 'Bluesy_guitar.mp3')

               

              And it's still giving me the same error:

              Can not open file descriptor: /data/data/com.rhomobile.pimalerts/rhodata/apps/data/data/com.rhomobile.pimalerts/rhodata/apps/public/Bluesy_guitar.mp3: open failed: ENOENT (No such file or directory)

                • Re: Alert.play_file not working

                  Put files in /public/alerts folder

                   

                  And use:

                   

                  Alert.play_file("/public/alerts/Bluesy_guitar.mp3")

                    • Re: Alert.play_file not working

                      Alert.play_file("/public/alerts/Bluesy_guitar.mp3")  Works perfect! thx!

                      • Re: Alert.play_file not working

                        Thank you! That worked like a charm!

                          • Re: Alert.play_file not working

                            Hello, today I tried to use Alert.play_file, but it does not working in my simulator, I used the system-api-test. it just does not working.

                              • Re: Alert.play_file not working

                                You tried it in the RhoSimulator?

                                  • Re: Alert.play_file not working

                                    yes, I am using the RhoSimulator

                                      • Re: Alert.play_file not working

                                        Where have you stored your file?

                                        And what does the code look like?

                                          • Re: Alert.play_file not working

                                            I run the exact rhodes-system-api-samples

                                             

                                            index.erb like this

                                            <%= link_to '[Play 20 Flip Strings.mp3]', { :action => :play_file_1, :query => {:file_name => '/public/alerts/20 Flip Strings.mp3'} }%><br/>

                                                <%= link_to '[Play information_bar.wav]', { :action => :play_file_1, :query => {:file_name => '/public/alerts/information_bar.wav'} }%><br/>

                                             

                                            controller.rb

                                            def play_file_1

                                                @flash = "Play file page"   

                                                Alert.play_file @params['file_name']

                                                render :action => :index, :back => '/app'

                                              end 

                                             

                                            the files are in the /public/alerts folder, I saw the files are there.

                                             

                                            Could you run the alert of system-api-samples?

                                              • Re: Alert.play_file not working

                                                I have run it before already and it worked for me.

                                                I posted this question initially because I was having a problem playing the file at first.

                                                 

                                                Try adding parentheses around the play_file parameter:

                                                 

                                                def play_file_1
                                                     @flash = "Play file page"
                                                     Alert.play_file( @params['file_name'] )
                                                     render :action => :index
                                                end
                                                

                                                 

                                                Might be something as simple as that.

                                                  • Re: Alert.play_file not working

                                                    Could you run it one more time on your simulator?

                                                    I tried the parentheses, same result, no sound.

                                                    Is that because I installed the latest version of rhode studio?

                                                     

                                                    My environment is windows 7

                                                      • Re: Alert.play_file not working

                                                        Can you show me your logs when you try playing the file?

                                                        It's not working for me now either.

                                                          • Re: Alert.play_file not working

                                                            We just tested on the real windows mobile device, it is working to play the 2 files.

                                                            Does it mean it is not working on the simulator?

                                                             

                                                            Here is the log in my simulator:

                                                            I 07/13/2012 14:37:47:278 00001a08           MainWindow| WebView: URL changed

                                                            I 07/13/2012 14:37:47:279 00003688           HttpServer| GC End.

                                                            I 07/13/2012 14:37:47:281 00001a08           MainWindow| WebView: loaded

                                                            I 07/13/2012 14:37:50:700 00001a08           MainWindow| WebView: loading...

                                                            I 07/13/2012 14:37:50:702 00003688           HttpServer| Process URI: '/app/Alert/play_file_1'

                                                            I 07/13/2012 14:37:50:702 00003688                  APP| RHO serve: /app/Alert/play_file_1

                                                            I 07/13/2012 14:37:50:702 00003688                  APP| Params: {"file_name"=>"/public/alerts/20 Flip Strings.mp3"}

                                                            I 07/13/2012 14:37:50:702 00003688                  APP| eval_compiled_file : C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/Alert/index.erb

                                                            I 07/13/2012 14:37:50:703 00003688                  APP| eval_compiled_file : C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/simplelayout.erb

                                                            I 07/13/2012 14:37:50:703 00003688  RHO AlertController| Layout file: C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/simplelayout.erb. Content size: 1279

                                                            I 07/13/2012 14:37:50:704 00003688           HttpServer| GC Start.

                                                            I 07/13/2012 14:37:50:704 00003688           HttpServer| GC End.

                                                            I 07/13/2012 14:37:50:704 00001a08           MainWindow| WebView: URL changed

                                                            I 07/13/2012 14:37:50:706 00001a08           MainWindow| WebView: loaded

                                                            I 07/13/2012 14:37:54:588 00001a08           MainWindow| WebView: loading...

                                                            I 07/13/2012 14:37:54:598 00003688           HttpServer| Process URI: '/app/Alert/play_file_1'

                                                            I 07/13/2012 14:37:54:599 00003688                  APP| RHO serve: /app/Alert/play_file_1

                                                            I 07/13/2012 14:37:54:599 00003688                  APP| Params: {"file_name"=>"/public/alerts/information_bar.wav"}

                                                            I 07/13/2012 14:37:54:599 00003688                  APP| eval_compiled_file : C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/Alert/index.erb

                                                            I 07/13/2012 14:37:54:600 00003688                  APP| eval_compiled_file : C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/simplelayout.erb

                                                            I 07/13/2012 14:37:54:600 00003688  RHO AlertController| Layout file: C:/Users/steve.zhang.COMPLETEINNOVAT/workspace/rhodes-system-api-samples/app/simplelayout.erb. Content size: 1279

                                                            I 07/13/2012 14:37:54:601 00001a08           MainWindow| WebView: URL changed

                                                            I 07/13/2012 14:37:54:602 00001a08           MainWindow| WebView: loaded

                                                            I 07/13/2012 14:37:54:606 00003688           HttpServer| GC Start.

                                                            I 07/13/2012 14:37:54:607 00003688           HttpServer| GC End.

                                    • Re: Alert.play_file not working
                                      Marcus Atkins

                                      Hi all,

                                       

                                      Have got the alerts working, however I did run into a few issues:

                                       

                                      1. Sound never played through the RhoSimulator

                                      2. '/public/alerts/sound.mp3' path did not work (use Rho.RhoFile.join(Rho.RhoFile.join(Rho.Application.publicFolder, 'assets'), 'sound.mp3)))

                                       

                                      The code to get the sound to play (in javascript):

                                       

                                      function playSuccessAlert(){

                                        Rho.Notification.playFile(Rho.RhoFile.join(getAlertsLocation(), 'sound_success_alert.mp3'));

                                      }

                                       

                                      function getAlertsLocation(){

                                        return (Rho.RhoFile.join(Rho.Application.publicFolder, 'alerts'));

                                      }

                                       

                                      Hopefully this will help someone out in the future.