rashrf / dab-web-player

plays an edi (DAB) stream which is delivered via http in the browser

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Attention! Beta phase.

At the moment there are still considerable performance problems. These problems will be fixed in the coming months. Also the API could change several times.

ediPlayer simple api

this repo contains only the compiled files that can be directly integrated into your browser. The whole toolchain to create the ediStreaming lib still consists of too many manual steps, but will also be published here or in its own repo.

In order to understand more precisely which components the Lib is composed of, a look can be taken at the following system overview drawing

Getting Started

to understand how to use the ediStreaming lib, look at the example in app.js.

to run the demo you can check out this repo and run it. however you need a webserver to do this.

you can also have a look at http://mpattest.irt.de/hradio/simpleApi. it runs this repo.

add ediPlayer.js to your dom. this file will also load irtdab.js and irtdab.worker.js. make sure all files are part of your project.

the minimal example contains materialize files. materialize is not a dependecy of the ediPlayer library.

API

Methods

ediPlayer.start([{url:'http://example.com/ediStream'}])

starts streaming data and Audiodecoding, when you call the function for the first time, an url must be passed. after that, this is no longer necessary. for compatibility reasons, startStream() also exists.

ediPlayer.stop()

stops audio decoding and streaming data

ediPlayer.seek(ms)

if timeshift is supported by the EDI server (the timeShiftControllerAvailable is thrown), the EDI stream can be set to a time relative to now in milliseconds. ediPlayer.seek(3600e3) sets the edistream an hour ago

ediPlayer.seekUts(uts)

the same as ediPlayer.seek() only that the time is specified as absolute Unix time in Milliseconds. ediPlayer.seekUts(new Date() - (1e3 * 60 * 5)) jumps 5sec back.

ediPlayer.toggleId(id)

the same as ediPlayer.seek() only that the jump marker is passed over an ID to jump to defined positions. these positions come from the items-array that is available through the itemsevent

ediPlayer.next()

same as ediPlayer.seek(), only that the time you jump to is from the list of toggle items and is relative to the current position of the stream. the stream is set to the beginning of the following item. However, this only works, if the service delivers toggles.

ediPlayer.prev()

same as ediPlayer.next(), only if an item ran longer than 3 seconds, it jumps to the beginning of the current item, otherwise to the beginning of the previous item.

Properties

ediPlayer.state

represents the current player state. it can be running or stopped.

ediPlayer.audioCtx

this lib uses in the background the web Audio API. To increase control possibilities, this property provides the corresponding baseAudioContext.

Events

you can register for events and define corresponding functions for them.

ediPlayer.addEventListener(type, (arg) => {console.log(arg)})

ediPlayer.removeEventListener(type, function)

type can be one of the following events.

event description argument
sls Slide Show Service - DAB images
example argument:
{
  "contentName": "f851.jpg",
  "clickThroughUrl": "",
  "contentSubType": 1,
  "triggerTime": "now",
  "categoryId": 0,
  "categoryTitle": "",
  "isCategorized": false,
  "slideId": 0,
  "url": "blob:http://localhost:9000/99465a13-3c50-4768-a388-7c4586000391"
}
dls Dynamic label Service - Text
example argument:
{
    "dlsObject": {
        "dynamicLabel": "Lana Del Rey - Video Games",
        "charset": 0,
        "itemToggle": true,
        "itemRunning": true,
        "dlPlusTags": {}
    },
    "dls": "Lana Del Rey - Video Games",
    "dlsp": {
        "ITEM_TITLE": "Video Games",
        "ITEM_ARTIST": "Lana Del Rey"
    }
}
stateChange info about edi player state could be running or stopped
missingSharedArrayBuffer not every browser has SharedArrayBuffer activated by default. dab encoding will not work without SharedArrayBuffer.

This event has no event-object as argument passed to the registered function.

A description of SharedArrayBuffer follows.

The SharedArrayBuffer object is not available.

In Chrome go to chrome://flags/#shared-array-buffer to enable this feature.

In FireFox go to about:config look for javascript.options.shared_memory and set it to true

Audio is not available in FireFox at the moment, but meta-data are coming in.

Note that SharedArrayBuffer was disabled by default in all major browsers on 5 January, 2018 in response to https://meltdownattack.com Spectre.

Chrome https://bugs.chromium.org/p/chromium/issues/detail?id=821270 re-enabled it in v67 on platforms where its site-isolation feature is enabled to protect against Spectre-style vulnerabilities.

msg some system messages like notifications and error messages. the EventObject has at least two properties.

msg: the notification itself as string

code: a message code

depending on code there are some more properties.



Some codes are: afBroken, noStreamData, audioZero, networkError

{
    code: "noStreamData"
    msg: "No data has been received from the streaming server for a few seconds. Is there a problem?"
}

or

{   
    code: "afBroken"
    msg: "af seq counter broken", 
    seq: 60447, 
    lastSeqCounter: 60445, 
}
serviceInfo is thrown if the current service name and ensemble name is available
{
    ensembleLabel: 'Antenne',
    serviceLabel: 'Bayern'
}
timeShiftControllerAvailable is thrown if the current edi server supports TimeShift.

As argument an object is passed which consists of the maximum timeshift buffer size in milliseconds and a timeshift token. The timeshift token can be used to design multidevice senarios by transferring the token to another device.

To start the same stream at the same position on another device, the timeshift token is appended to the stream URL as get parameter. If the timeShiftControllerAvailable-event returns the same timeshift token, it is possible to control the stream from both devices.
{
    'Timeshift-Max': 360000
    'Timeshift-Token': 'dsfh2345kh3'
}
items an array consisting of item-running elements.
    items-Array
[
    {
        "label": "Talisco - Sun",
        "tags": [
            {
                "type": 1,
                "typeDescription": "ITEM_TITLE",
                "text": "Sun"
            },
            {
                "type": 4,
                "typeDescription": "ITEM_ARTIST",
                "text": "Talisco"
            }
        ],
        "toggleState": true,
        "runningState": true,
        "time": 1574668398548,
        "id": 314010,
        "slidePath": "",
        "slideMime": ""
    },
    ......
]
    
liveItem Items that are transferred at runtime. The structure corresponds to the elements from the items-array. (see items event) one Object from items array (see items event)
unhandeldEdiTag An EDI tag was found in the stream that was not further handled. this is especially the case for custom edi tags. {tagName, payLoad}
payload: uint8Array
dabTime Time from the DAB stream js Date-Object (new Date())

About

plays an edi (DAB) stream which is delivered via http in the browser


Languages

Language:JavaScript 63.9%Language:HTML 36.1%