Is there no shell.mode 1 in Linux?

I will use ‘play’ to play a sound, because sound.play does nothing.

[code] dim sh as new shell

if f <> nil and f.Exists then
sh.mode = 1
sh.Execute "/usr/bin/play -v 0.7 " + f.ShellPath
end [/code]

it works with shell.mode=0, but not with mode 1 or mode 2

(Xojo2015R1 and R4, Elementary OS 32bit, 3.2.0-97-generic-pae)

I think the issue maybe from using a dim instead of a property. In mode 1 the event ends too soon for the asynchronous shell to execute.

Both mode 1 and 2 work. I have tested 1 with

ls > test.txt

Which works fine, I see the content of the directory in test.txt.

Mode 2 works just fine in the example Interactive shell.

This plays just fine here in Linux Mint :

sh is a shell property of the window, so it keeps its scope when the event ends.

sh = new shell dim f as folderitem = SpecialFolder.Desktop.child("Ding.wav") if f <> nil and f.Exists then sh.mode = 1 sh.Execute "/usr/bin/play -v 0.7 " + f.ShellPath end

I was not able, however, to play an mp3 :
/usr/bin/play FAIL formats: no handler for file extension `mp3’

Thanks, with property it works. (mp3 plays)

This should be mentioned in the LR

I would double test under other distros for mp3. In Linux Mint 13, obviously, it simply does not work. That could be an issue when you distribute your software.

42248 - (Documentation) LR should recommend using a property or subclassing shell when using modes 1 and 2
Status: Needs Review Rank: Not Ranked Product: Xojo Category: N/A

Michel Bujardet Today at 10:16 AM
See Is there no shell.mode 1 in Linux? - Linux - Xojo Programming Forum

At Page Not Found — Xojo documentation the example shows Mode 2 used with a Dim.

IMHO, that should apply only to mode zero.

In Mode 1 and 2, Shell should be used as a property or as a subclass, otherwise shell execute will not happen since property gets out of scope before the asynchronous operation can take place.

Maybe a phrase should be added to the LR to advise users and prevent them to hit that issue.

<https://xojo.com/issue/42248>

[quote=242092:@Axel Schneider]Thanks, with property it works. (mp3 plays)

This should be mentioned in the LR[/quote]

That the object going out of scope kills it ?
That is perfectly normal

  sh = new shell
  dim f as folderitem = SpecialFolder.Desktop.child("theSongFile.mp3")
  if f <> nil and f.Exists then
    sh.mode = 1
    sh.Execute "/usr/bin/play -v 0.7 " + f.ShellPath
    Do
      sh.Poll
    Loop Until Not sh.IsRunning
  end

[quote=242089:@Michel Bujardet]I was not able, however, to play an mp3 :
/usr/bin/play FAIL formats: no handler for file extension `mp3’
[/quote]
Add that Do Loop so that the shell keeps running until the play completes.

means the (sox) mp3 codec is missing.

sudo apt-get install libsox-fmt-mp3

[quote=242195:@Norman Palardy]That the object going out of scope kills it ?
That is perfectly normal[/quote]
No - that if you’re waiting for the process that you exec’d in the Mode 1 or 2 shell to complete, you need to loop after you execute until sh.IsRunning = False.

Sorry, but it is a whole lot simpler to use a property. Besides, looping defeats the entire concept of event driven. In practice it freezes execution in an event, possibly of the UI and require App.DoEvents, instead of relying on the shell Completed event. Unless using it in a Console program, looping is very old thinking.

@Michel Bujardet - My reference is related to the manner in which Axel was trying to accomplish the playback. If you don’t loop on a mode 1 or 2, the task simply falls through without waiting for the completion of the executed task.

There are many ways to skin a cat, and this one happens to fit the model that he put forth in his original code sample.

In his instance, I’d rather use the movie player.

In some Linux distributions the Movie Player is not working. (as well Sound.play)

Linux user and developer since 1993 soap box mode engaged:

That’s where you’ll need to explicitly define your prerequisites.

Every modern Linux distribution includes gplayer and the associated parts, so the Xojo MoviePlayer should work. Therefore, you should either tell the user it’s required, or catch that it’s not installed/failing and not play the sounds.

There is only so much that you can do (or feel responsible to do) to resolve the stupidity in the 100’s of Linux distributions out there and their creators’ ideas of what a Linux system should include. Set your requirements and stick to them. If gplayer is one of them, make it so.

that confuses me, gplayer is a python player.

I use Elementary OS Luna 32-bit.
I can not use a ‘modern Linux distribution’ on my old notebook (Samsung R60Plus, Core2Duo, ATI Radeon Xpress 1250),
because the support for older ATI graphic cards is bad.

The key was “… and associated parts”. gplayer is the graphical front end for mplayer. The mplayer backend stuff is what will allow Xojo to play movies and audio files on Linux. You should be able to install mplayer on even your old system. In fact, I’ll wager that you can get it for your distribution using “sudo apt-get install mplayer”.

mplayer already exists, it does not work anyway.

I frankly admire Linux Desktop developers. Mac is already a pain with regular change of system, but I cannot imagine dealing with over 100 distributions.

@Axel Schneider - I’m going to build a Luna box and will find out what’s occurring.

And Windows is just a pain. No system change needed.

:wink:

[quote=244757:@Markus Winter]And Windows is just a pain. No system change needed.

;)[/quote]

And you are an ignorant.

Well, working with Windows since Windows 3.1 (around 1991), Mac since System 6 (the old System 6, not yet OS X, around 1990), and Linux since Red Hat 5 (though only dabbling, not really working), plus building, repairing, upgrading, and setting up about 700 PCs and around 150 Macs, has undoubtedly given me a certain appreciation of the different strengths and weaknesses of the respective systems, though that in no way impacts on my status as ignoramus maximus … :stuck_out_tongue:

But maybe I’m just sore because my blasted high-end PC is out of action again … :frowning:

P.S. Come on, Michel, if you can dish it out then you should be able to take it too :wink: