2
$\begingroup$

I am trying to deploy a CDF file with a small animation that does the following: when the button is pressed, it plays a sound and displays a spectrogram ; while the sound plays, a red progress line moves across the spectrogram to indicate where we are at.

workin applet

As you can see in the following screen capture, the code (see below) works fine within Mathematica and in the exported CDF file as long as it’s played by Mathematica. However, when played within the Free CDF Player, I get the correct sound but not the progress line and the graphic is red, which indicates a problem. Sadly, it does not generate any error message.

screen capture

What am I doing wrong ?

Here is the code:

SetDirectory[NotebookDirectory[]];
CDFDeploy["test.cdf", DynamicModule[{sound, astream, bg, dim},
   Column[{Dynamic@Show[ImageCompose[bg,
        Graphics[{Red,InfiniteLine[{(.2 + QuantityMagnitude@astream["Position"])/QuantityMagnitude@Duration[sound]*dim[[1, 2]] , 0}, {0,1}]},
                 PlotRange -> dim]], ImageSize -> {Automatic, 200}],
        Button["Play", AudioPlay[astream]]}],
   Initialization :> (
     sound = ExampleData[{"Audio", "PianoScale"}];
     astream = AudioStream[sound];
     bg = Rasterize[Grid[{
         {AudioPlot[sound, ImageSize -> 500, FrameTicks -> None]},
         {Spectrogram[sound, ImageSize -> 500, FrameTicks -> None]}
         }]];
     dim = Transpose[{{0, 0}, ImageDimensions[bg]}];
     )]];

I tried using SaveDefinitions instead of Initialization ; I tried exporting directly to a CDF (with the menus) instead of CDFDeploy. But the problems is always the same. Thanks !

PS. The motivation for this question : the file is to be deployed to a large community of students that only have access to the Free CDF Player but not to Mathematica, nor the Pro Player.

$\endgroup$
4
  • $\begingroup$ First check DynamicModule, there are three errors Show::gtype: ImageCompose is not a type of graphics. The specified setting for the option GraphicsBoxOptions, PlotRange cannot be used. ConicHullRegion[{Part[$CellContextdim$$, 1, 2] (0.2 + QuantityMagnitude[$CellContextastream$$["Position"]])/QuantityMagnitude[Duration[$CellContextsound$$]], 0}, {{0, 1}}] is not a valid ConicHullRegion specification.` $\endgroup$ Aug 1, 2018 at 7:29
  • $\begingroup$ @Alex Trounev: that’s strange. I don’t get any of those error messages on MMA 11.3.0.0 (as stated, on my side, it works flawless on MMA, just not in CDF) ; how did you get them ? I don’t call ConicHullRegion at least not that I know of so I am curious how can it be quoted in your error message ? I just checked with FullForm: bg is an Image[] ; I tried changing bg=Rasterize[...] to bg=Rasterize[...,"Graphics"] so both arguments of Show are Graphics[] but it does not solve the issue. $\endgroup$ Aug 2, 2018 at 1:19
  • $\begingroup$ Francois Vigneron, I'm sorry, I checked it again, there are no mistakes. Apparently, there was interference with another program. $\endgroup$ Aug 2, 2018 at 3:58
  • $\begingroup$ This may help you get the generated error messages while running inside the CDF player: mathematica.stackexchange.com/a/181013/251 $\endgroup$ Aug 31, 2018 at 18:04

1 Answer 1

1
$\begingroup$

It seems that the initialization and rendering of audio controllers takes enough time to get the front end confused. Here is a slightly changed version which work in cdf. Except the audio plot is not so smooth as in MMA.

CDFDeploy["test.cdf", DynamicModule[
  { sound, astream, bg, dim
  , display = ProgressIndicator[Appearance -> "Percolate"]
  }
, Dynamic[display, TrackedSymbols :> {display}]
, Initialization :> (
    sound = ExampleData[{"Audio", "PianoScale"}];
    astream = AudioStream[sound];
    bg = Rasterize[
      Grid[{{AudioPlot[sound, ImageSize -> 500, 
          FrameTicks -> None]}, {Spectrogram[sound, ImageSize -> 500, 
          FrameTicks -> None]}}]];
    dim = Transpose[{{0, 0}, ImageDimensions[bg]}];
    display = Column[{Dynamic[
        Show[
         ImageCompose[bg, 
          Graphics[{Red, 
            InfiniteLine[{(.2 + 
                  QuantityMagnitude@astream["Position"])/
                QuantityMagnitude@Duration[sound]*dim[[1, 2]], 0}, {0,
               1}]}, PlotRange -> dim]], ImageSize -> {Automatic, 200}]
        ], Button["Play", AudioPlay[astream]]}])
, SynchronousInitialization -> False
]]
$\endgroup$
2
  • $\begingroup$ good idea to use ProgressIndicator to give the applet something to display while waiting. But sadly your solution still does not work in CDF Player 11.3.0.0 : I get the initial progress bar, but when the main screen kicks in, the image is red and does not show the line at all (like before). Works perfect when MMA opens the CDF, but not when the CDF Player does :-( $\endgroup$ Aug 2, 2018 at 1:00
  • $\begingroup$ @FrancoisVigneron will try to catch this once I install 11.3 player. I tested on 11.2 and I was able to reproduce the problem as well as the fix was working. Yeah, it is a pain when CDF does not work even if you use with respect to its limitations :/ $\endgroup$
    – Kuba
    Aug 2, 2018 at 5:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.