Page 1 of 1

Jython Sound and Image Processing

PostPosted: Wed Apr 05, 2017 9:29 am
by alvin.murphy@navy.mil
Does the Cameo Jython implementation support the use of sound and video methods? Do I need to import a module or add something to my MagicDraw directory?

Re: Jython Sound and Image Processing

PostPosted: Thu Apr 06, 2017 2:28 am
by tomas.lukosius@nomagic.com
Hello Alvin Murphy,

It is possible to play basic sound using java api. Following example code shows how to play wave sound:

Code: Select all
from javax.sound.sampled import AudioInputStream, AudioFormat, DataLine, AudioSystem, Clip
from java.io import InputStream, FileInputStream, File

yourFile = File("path to file *.wav")
stream = AudioSystem.getAudioInputStream(yourFile)
format = stream.getFormat()
info = DataLine.Info(Clip, format)
clip = AudioSystem.getLine(info)
clip.open(stream)
clip.start()


If you need to play compressed audio formats, like mp3, or video formats, then you will need to rely on some 3rd party library. We did not test any of them, so we cannot provide any recomendations, but we think, that technically it is possible.

Kind regards,
No Magic, Inc. Customer Support

Re: Jython Sound and Image Processing

PostPosted: Thu Apr 06, 2017 3:15 pm
by alvin.murphy@navy.mil
Thank you! Thank worked perfectly.

Is there a way to access the file from the current Project Directory without specifying the full path name?

I used the following:

Code: Select all
yourFile = File("C:\\Users\\alvin.murphy\\Music\MySound.wav")


I need an easy way to share the model without having the user update the path within the script.

Thanks.

Re: Jython Sound and Image Processing

PostPosted: Fri Apr 07, 2017 2:03 am
by tomas.lukosius@nomagic.com
You can get project directory with following code:

Code: Select all
from com.nomagic.magicdraw.core import Application
from java.io import File

projectFilePath = Application.getInstance().getProject().getFileName()
projectFile = File(projectFilePath)
projectDir = projectFile.getParent()
# append your media file name


Kind regards,
No Magic, Inc. Customer Support