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

Evgeny Vovchenko
http://docs.rhomobile.com

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

use get_public_folder()

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
So what I did was replace

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)

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Evgeny Vovchenko
Put files in /public/alerts

Put files in /public/alerts folder

And use:

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Darryn Campbell
Thank you! That worked like a

Thank you! That worked like a charm!

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
Hello, today I tried to use

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
You tried it in the

You tried it in the RhoSimulator?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
yes, I am using the

yes, I am using the RhoSimulator

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
Where have you stored your

Where have you stored your file?

And what does the code look like?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
I run the exact rhodes-system

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?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
I have run it before already

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
Could you run it one more

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
Can you show me your logs

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

It's not working for me now either.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
We just tested on the real

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
If you check your error log.

If you check your error log.

Does it say anything about the resource ebign out of sync with the file system?

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Steve Zhang
I did not find any out of

I did not find any out of sync like error

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Ariana Habbaba
It definitely works on the

It definitely works on the simulator because I've done it before.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Manuel Stiem
Alert.play_file("/public

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

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Marcus Atkins
Hi all,Have got the alerts

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.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments