Skip to content

matthias-wolff/MusicBookPlayer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MusicBookPlayer ⟩⟩ Demo

DHTML audio player displaying booklet pages for audio tracks and parts of audio tracks.

Cover Page Example Part-of-Track Page Example Contents Page Example
MusicBookPlayer: Cover page example MusicBookPlayer: Cover page example MusicBookPlayer: Cover page example

Contents
1 Introduction
2 Create Your Own Music Book
  2.1 Prerequisites
  2.2 Setup
  2.2 Customization
3 API Documentation
4 Tested Configurations
References

1 Introduction

A music book is playlist of audio tracks, each accompanied by an image and an optional description text – much like a good old-fashioned audio CD with a booklet. Each audio track may be split into several parts which show their own images and description texts. A music book is structured as follows:

  1. Cover page (1×)
  2. Audio pages (n×, one per audio track or serveral part pages per audio track)
  3. Contents page (1×)

MusicBookPlayer is a DHTML/Javascript-based player for music books. It features audio controls (play/pause, time rail), play list controls (next, previous, contents), and a live audio spectrum analyzer – see screenshots above.

Click here to see a demo.

2 Create Your Own Music Book

The MusicBookPlayer library is to allow you creating your own music books. It is optimized for smartphones but it will work on tablets and desktop devices as well. MusicBookPlayer will run locally and on webservers.

2.1 Prerequisites

To setup your own music book, you need the following:

  1. a bunch of audio files1)
  2. a cover image for the book2)
  3. an image for each page of the book2)
  4. optionally, a description text for the book and for each page3)

1) preferably MP3s
2) preferably square JPEGs, e.g. 600 x 600 px
3) may contain HTML markup

2.2 Setup

  1. Create a folder for the music book on your local device or your webserver and copy the audio and image filesyour book to that folder (see demo folder for an example).
  2. Create an index.html file containing the following code in the music book folder:
<!DOCTYPE html>
<html lang="en-US">
<head>
  <meta charset="utf-8"/>
  <meta http-equiv="Content-Type" content="text/html"/>
  <meta name="viewport" content="width=device-width, initial-scale=1"/> 
  <link rel="shortcut icon" href="https://matthias-wolff.github.io/MusicBookPlayer/img/MusicBookPlayer.ico"/>
  <link rel="icon" href="https://matthias-wolff.github.io/MusicBookPlayer/img/MusicBookPlayer.ico"/>
  <link rel="stylesheet" type="text/css" media="screen" href="https://matthias-wolff.github.io/MusicBookPlayer/css/styles.css"/>
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script type="text/javascript" src="https://matthias-wolff.github.io/MusicBookPlayer/js/mediaelement-and-player.min.js"></script>
  <script type="text/javascript" src="https://matthias-wolff.github.io/MusicBookPlayer/js/musicbookplayer.js"></script>
</head>
<body>

  <!-- Initialize Music Book here -->  
  <script type="text/javascript">
    MusicBookPlayer.create({              // Create music book (see API description below)
        //mediaBaseURI: document.baseURI, // Can be omitted when document base URI
        title : 'Music book title',       // Mandatory
        artist: 'Music book artist',      // Mandatory
        image : 'CoverImage.jpg',         // Mandatory 
        descr : 'Music book descripion',  // Optional
      });
    MusicBookPlayer.addAudioPage({        // Add an audio page (see API description below)
        title : 'Track title',            // Mandatory for tracks
        audio : 'TrackAudio.mp3',         // Mandatory for tracks
        image : 'TrackImage.jpg',         // Mandatory but not enforced
        descr : 'Track description',      // Optional
      });
    // More audio pages...
    MusicBookPlayer.addTocPage();         // Add table-of-contents page (see API description below)
  </script>

  <!-- Create spectrum analyzer (must be at end of page body!) -->
  <script src="https://matthias-wolff.github.io/MusicBookPlayer/js/audioMotion.js" type="module"></script>

</body>
</html>
  1. Optionally: If you want to host an own installation of MusicBookPlayer, check out or fork the MusicBookPlayer library and copy the contents to a local folder or to a folder on your webserver. In the index.html file of your music book, replace all occurrances of https://matthias-wolff.github.io/MusicBookPlayer/ by the URL of your copy of the MusicBookPlayer library.
    Note: All *.md files and the demo folder of your copy can be deleted.
  2. Initialize your music book in Javascript section <!-- Initialize Music Book here --> of index.html (see API Documentation below).

2.3 Customization

The player skin is competely controlled by a stylesheet. Download css/styles.css, modify it to your needs and have your HTML include your style file instead of the default one – that's it.

3 API Documentation

MusicBookPlayer is implemented as a singleton, i.e., you can have only one instance per HTML page. If you want multiple instances, please use &lt;frame&grt;s or &lt;iframe&grt;s. To create your own music book you will need only three static methods:

  1. MusicBookPayer.create(props),
  2. MusicBookPayer.addAudioPage(props), and
  3. MusicBookPayer.addTocPage().

Click here to see the full documentation.

static MusicBookPayer.create(props)

Creates the MusicBookPlayer pseudo-singleton. If the object is already existing, the method just returns it. If the singleton is not yet existing, the method creates it and writes the MusicBookPlayer HTML page into the current document.

Parameters:

NameTypeDescription
propsObjectMusic book properties
Properties
NameTypeAttributesDescription
mediaBaseURIstring<optional>Absolute base URI of the book's
media files, i.e., audio and image
files. If omitted, the HTML document
base URI will be used, which means
that themedia files are located in the
same folder as index.html.
titlestring Music book title
artiststring Artist name
imagestring Cover image URL, absolute or relative
to mediaBaseURI
descrstring<optional>Description text, may contain HTML

Returns:

The singleton. The object is also stored in MusicBookPlayer.instance and can later be retrieved by MusicBookPlayer.getInstance().

static MusicBookPayer.addAudioPage(props)

Adds a new audio page to the MusicBookPlayer. If a TOC page exists, the method will update the TOC.

Parameters:

NameTypeDescription
propsObjectPage properties
Properties
NameTypeAttributesDescription
titlestring Page title1)
artiststring<optional>Artist name2)
audiostring Audio URL3) 4)
imagestring Image URL4)
descrstring<optional>Description text, may contain HTML
partstring<optional>Part title. If page is a track, the part title
can be used as a subtitle.
poffsfloat<optional>The time offset in seconds if the page is
part of a track5)
Footnotes
1) If omitted, the title of the previous page will be copied if a previous page
exists. Otherwise, the method will throw an exception.
2) If omitted, the book's artist name will be used.
3) absolute or relative to mediaBaseURI, see method create()
4) Mandatory for tracks, omit for parts! Method will throw an exception if the
audio property is missing creating a track page. Track audio URLs must be
unique throughout the music book!
5) Mandatory for all parts in a sequence of parts except the first one, omit for
tracks! Method will throw an exception of the ptoffs property is missing
creating the 2nd, 3rd, etc. part of a track.

Returns:

The newly created page

static MusicBookPayer.addTocPage()

4 Tested Configurations

Browser Version OS MusicBookPlayer Particular Issues
Chrome 93.0 Android r89 (8afa629) none
Chrome 93.0 Windows 10 r89 (8afa629) none
Edge 93.0 Windows 10 r89 (8afa629) none
Firefox 91.4 Android r89 (8afa629) none
Firefox 93.0 Windows 10 r89 (8afa629) none
Safari 14.1 Big Sur r89 (8afa629) none
Safari 14.6 iOS (iPad) r89 (8afa629) init: play button grey
Samsung 9.0 Android r89 (8afa629) none
UC 12.10 Android r89 (8afa629) no spectrum analyzer
all all iOS (iPhone) r89 (8afa629) big problems...

More to be tested. Help wanted (see issue #2)!

References