Assets Filepath

1 Like

After some experimentation I decided that SAF1.OpenSingleDocument which opens at the required directory was better than trying to construct my own file selection list with AI2 ListView etc. The only difficulty with SAF1.OpenSingleDocument was with the Mime Types relating to a particular type of text file. An *.abc (which is abcNotation for music) is not a recognised mime type despite the format having been around since about 1997 and hunderds of thousands of files in existance. I used Mime Type ‘application/octet-stream’ as a wildcard which gets round the problem – but probably not good practise.

To help others with similar issues, the following app demonstrates

  • using SAF1.OpenSingleDocument to make a file selection
  • incorpoorating JavaScript and HTML and CSS files into a user app (placed in Assets)
  • using AI2 WebViewer to display the JavaScript output
  • using window.AppInventor.getWebViewString() to pass data into JavaScript
  • plus odds and ends eg: CSS font-size vw/vh, button management

SAF1OpenSingleD o cument is used to select a music file of either *.mp3 or *.abc from Music/Bodhran/MP3 or Music/Bodhran/ABC directories. If you wish to run the app you can either (a) set up the above directories and copy a few tunes into them or (b) edit the Uri reference to a directory of your choice. Some sample *.mp3 and *.abc files are appended.

Depending on the music format selected (determined by filename extension) the file is passed to the AI2 Player 1 if *.mp3 or if *.abc passed to JavaScript. Playing an *.mp3 is trivial, but the *.abc process is somewhat more interesting.

In essence the JavaScript parses the *.abc textfile and produces (a) the sheet music score and (b) a sound file. WebViewer displays the music score (may need to scroll down to see it), with the notes animated when playing. The nice thing about the *.abc player is that the tempo can be changed which is great if you are trying two learn to play a new piece of music.

The JavaScript is in part embedded within the HTML and in part called from an ABCJS library, (see https://www.abcjs.net/) which has an extensive range of procedures, of which only a few are used in this demo.

Enough said, better just to have a look if interested. Best viewed on a tablet, but music score will squeeze onto a phone screen. An internet connection is required to pull in a piano soundfont to generate the JavaScript sound file.
SAF_ForBod2.aia (766.4 KB)

Having said I'd include a couple of sample music files I don't think they were uploaded???

3 Likes

You can use text/x-abc in place of that.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.