Android SDK (Core)
API Reference
78min
please find below an overview of the available apis for you to use also check out the guides & tutorials docid\ iw3qlop9opptsdgmgjw z chapter for useful information about using the sdk nwcore interface documentation the nwcore interface is a critical part of the sdk that provides functionalities for audio synchronization, experience playback, and the management of experimental manifest services it acts as a central point for accessing various services and functionalities required for the interactive and multimedia experiences offered by the sdk properties appid string the unique identifier for the application val applicationid = nwcore appid environment nwenvironment an instance that defines the operational environment settings val envsettings = nwcore environment // get the environment nwcore environment = nwenvironment prod // set the environment locale string the current locale of the application, typically used for localization val currentlocale = nwcore locale // get the locale nwcore locale = "en" // set the locale contentproviderurl string the url to the content provider that supplies media and experience data val providerurl = nwcore contentproviderurl // get the contentproviderurl nwcore contentproviderurl = <"contentproviderurl"> // set the contentproviderurl timelinesync nwtimelinesync an instance that handles synchronization with the timeline service val timelinesynchronization = nwcore timelinesync isnwsdkinitialized boolean a boolean flag indicating whether the sdk has been initialized if (nwcore isnwsdkinitialized) { // sdk has been initialized } functions audiosyncservice(expmanifestid string, synccontents synccontents) audiosyncservice? initiates an audio synchronization service for a given experience manifest returns an instance of audiosyncservice or null if the service cannot be initiated val audiosync = nwcore audiosyncservice("expmanifestid123", synccontents) audiosync? start() experienceplaybackservice(expmanifestid string, audiosyncservice audiosyncservice?) experienceplaybackservice creates a playback service for a specific experience manifest, optionally using an audio synchronization service val expplaybackservice = nwcore experienceplaybackservice("expmanifestid123", audiosync) expcomposeview( ) a composable function that renders a ui view for the experience playback service with optional gui overlay, audio synchronization callback, and various event handlers @composable fun experienceview() { nwcore expcomposeview( context = localcontext current, expplaybackservice = playbackservice, guioverlayurl = "https //example com/overlay", audiosynccallback = null, exitplayback = { / handle exit / }, oncheckaudiopermission = { / check permission / }, oncustomaction = { payload > / handle custom action / }, onerror = { exception > / handle error / }, modifier = modifier fillmaxsize() ) } expview(context context, expplaybackservice experienceplaybackservice, guioverlayurl string?, audiosynccallback audiosyncservice audiosynccallback? = null, exitplayback () > unit, oncheckaudiopermission () > unit, oncustomaction (payload string?) > unit = {}, onerror (exception nwexception?) > unit = {}) view creates a traditional android view for the experience playback service, similar in functionality to expcomposeview but for use outside of jetpack compose val view = nwcore expview( context = context, expplaybackservice = playbackservice, guioverlayurl = "https //example com/overlay", audiosynccallback = null, exitplayback = { / handle exit / }, oncheckaudiopermission = { / check permission / }, oncustomaction = { payload > / handle custom action / }, onerror = { exception > / handle error / }, ) { // configuration for exitplayback and other callbacks } checkaudiopermission(isgranted boolean) notifies the sdk of the current audio permission state nwcore checkaudiopermission(isgranted = true) getversionname() string returns the version name of the sdk val versionname = nwcore getversionname() println("sdk version $versionname") ondestroy() cleans up resources and shuts down services when the instance is no longer needed nwcore ondestroy() additional components @composable indicates that expcomposeview is a jetpack compose function, allowing it to be used within the compose ui toolkit devtools a property that provides access to developer tools for debugging and development purposes exception handling nwexception a custom exception type used for error handling within the sdk functions usage context this interface is designed to be implemented by the sdk and used by application developers to integrate multimedia and interactive experiences into their applications it abstracts the complexities involved in synchronizing audio, managing experimental manifests, and handling experience playback experienceplaybackservice interface documentation the experienceplaybackservice interface defines a comprehensive set of functionalities for controlling and managing playback of multimedia experiences, synchronization with audio, and handling of experience manifest data it offers detailed control over playback and synchronization states, allowing for a robust multimedia experience properties scope coroutinescope the coroutine scope associated with the playback service for managing asynchronous tasks val coroutinescope = experienceplaybackservice scope expmanifestid string the identifier of the current experience manifest val manifestid = experienceplaybackservice expmanifestid println("current experience manifest id $manifestid") isofflinefileavailable boolean indicates whether offline files are available for playback if (experienceplaybackservice isofflinefileavailable) { println("offline files are available for playback ") } else { println("no offline files available ") } islive boolean indicates if the current playback is a live experience if (experienceplaybackservice islive) { println("the current playback is a live experience ") } else { println("the current playback is not live ") } isplaybackmuted boolean reflects the current mute state of the playback if (experienceplaybackservice isplaybackmuted) { println("playback is currently muted ") } else { println("playback is not muted ") } isplaying boolean indicates if playback is currently active if (experienceplaybackservice isplaying) { println("playback is currently active ") } else { println("playback is not active ") } isprepared boolean shows whether the playback service is prepared to start playback if (experienceplaybackservice isprepared) { println("playback service is prepared for playback ") } else { println("playback service is not prepared yet ") } issynced boolean indicates whether the playback is synchronized with the audio sync service if (experienceplaybackservice issynced) { println("playback is synchronized with the audio sync service ") } else { println("playback is not synchronized ") } iscurrentlysynced boolean shows if the playback is currently in sync according to the latest checks if (experienceplaybackservice iscurrentlysynced) { println("playback is currently in sync ") } else { println("playback is currently out of sync ") } offlinecontent stateflow\<offlinecontent> a flow of offline content data for the current experience experienceplaybackservice offlinecontent collect { offlinecontent > println("offline content status ${offlinecontent status}") } audiosyncservice audiosyncservice? the audio synchronization service, if available val audiosync = experienceplaybackservice audiosyncservice audiosync? let { println("audio sync service is available ") } mediaplaybackservice mediaplaybackservice the service responsible for media playback functionalities val mediaservice = experienceplaybackservice mediaplaybackservice println("media playback service is ready ") activeglobalaudiotrackid stateflow\<string> the id of the currently active global audio track experienceplaybackservice activeglobalaudiotrackid collect { trackid > println("active global audio track id $trackid") } activevideoentityid stateflow\<string> the id of the currently active video entity experienceplaybackservice activevideoentityid collect { entityid > println("active video entity id $entityid") } playback control functions startsyncedplayback() starts playback that is synchronized with the audio sync service experienceplaybackservice startsyncedplayback() println("synced playback started ") startunsyncedplayback() begins playback without synchronization to the audio sync service experienceplaybackservice startunsyncedplayback() println("unsynced playback started ") resumeplayback() resumes playback from the current pause state experienceplaybackservice resumeplayback() println("playback resumed ") pauseplayback() pauses the currently playing experience experienceplaybackservice pauseplayback() println("playback paused ") stopplayback() stops the current playback entirely experienceplaybackservice stopplayback() println("playback stopped ") muteorunmuteplayback(ismute boolean, ismanualmute boolean = false) mutes or unmutes the playback based on the ismute parameter the ismanualmute indicates if the action was triggered manually experienceplaybackservice muteorunmuteplayback(ismute = true, ismanualmute = true) println("playback muted ") seekbackorforward(backorforward double) seeks the playback backward or forward by a specified amount of time in seconds experienceplaybackservice seekbackorforward(10 0) // forward 10 seconds println("playback seeked forward by 10 seconds ") jumpto(seekoffset double) jumps to a specific time offset in the playback experienceplaybackservice jumpto(60 0) // jump to 60 seconds println("jumped to 60 seconds in the playback ") switchactiveglobalaudiotrackbyentityid(entityid string?) switches the active global audio track based on the given entity id experienceplaybackservice switchactiveglobalaudiotrackbyentityid("entityid123") println("switched to the specified global audio track ") switchactivevideotrackbyentityid(entityid string?) switches the active video track based on the provided entity id experienceplaybackservice switchactivevideotrackbyentityid("entityid456") println("switched to the specified video track ") switchactiveglobalaudiotrack(trackid string? = null) changes the active global audio track to the one identified by trackid experienceplaybackservice switchactiveglobalaudiotrack("audiotrackid789") println("global audio track switched ") switchactivevideotrack(trackid string? = null) changes the active video track to the one identified by trackid experienceplaybackservice switchactivevideotrack("videotrackid012") println("video track switched ") startsyncvalidation() initiates validation of the current sync status experienceplaybackservice startsyncvalidation() println("sync validation started ") stopsyncvalidation() stops the ongoing sync validation process experienceplaybackservice stopsyncvalidation() println("sync validation stopped ") startliveplayback() begins playback of a live experience experienceplaybackservice startliveplayback() println("live playback started ") seeksyncedplayback() seeks the playback while maintaining synchronization experienceplaybackservice seeksyncedplayback() println("playback seeked with synchronization ") replayplayback() restarts the current playback from the beginning experienceplaybackservice replayplayback() println("playback replayed from the beginning ") restartplayback() restarts the playback, reinitializing any necessary services experienceplaybackservice restartplayback() println("playback restarted ") changeplaybackspeed(speed double) adjusts the playback speed a speed value of 1 represents normal speed experienceplaybackservice changeplaybackspeed(1 5) // 1 5x speed println("playback speed set to 1 5x ") changequality(height int) changes the playback quality based on the specified height parameter experienceplaybackservice changequality(1080) println("playback quality changed to 1080p ") sync functions initorupdatesynctimeline(position double?, syncstarttimems long?, resyncthreshold double?, isresync boolean) double? initializes or updates the synchronization timeline with optional parameters for position, start time, and resynchronization threshold val updatedposition = experienceplaybackservice initorupdatesynctimeline( position = 120 0, syncstarttimems = system currenttimemillis(), resyncthreshold = 5 0, isresync = true ) println("updated sync timeline position $updatedposition") issyncaccessible() boolean checks if synchronization functionalities are accessible val syncaccessible = experienceplaybackservice issyncaccessible() println("is sync accessible? $syncaccessible") startsync() starts the synchronization process for the current playback experienceplaybackservice startsync() println("synchronization started ") startresync() initiates a resynchronization process experienceplaybackservice startresync() println("resynchronization process initiated ") stopsync() stops the current synchronization process experienceplaybackservice stopsync() println("synchronization stopped ") experience manifest handling getexpmanifestservice() expmanifestservice retrieves the service for managing experience manifests val expmanifestservice = experienceplaybackservice getexpmanifestservice() getexpmanifest() expmanifestdata gets the current experience manifest data val expmanifestdata = experienceplaybackservice getexpmanifest() println("experience manifest id ${expmanifestdata id}") getexpmanifestobserver() stateflow\<expmanifestdata> observes changes to the experience manifest data val expmanifestobserver = experienceplaybackservice getexpmanifestobserver() expmanifestobserver collect { manifestdata > println("updated manifest id ${manifestdata id}") } isexpmanifestempty() stateflow\<boolean> checks if the current experience manifest is empty val ismanifestempty = experienceplaybackservice isexpmanifestempty() ismanifestempty collect { isempty > if (isempty) println("experience manifest is empty ") } getentities() stateflow\<list\<expmanifestentity>> retrieves a flow of entities defined in the current experience manifest val entitiesflow = experienceplaybackservice getentities() entitiesflow\ collect { entities > entities foreach { entity > println("entity id ${entity id}") } } getentity(entityid string?) expmanifestentity? gets a specific entity by its id from the experience manifest val specificentity = experienceplaybackservice getentity("entityid123") println("specific entity name ${specificentity? name}") getvideotracks() stateflow\<list\<expmanifestvideotrack>> retrieves a flow of video tracks from the experience manifest val videotracksflow = experienceplaybackservice getvideotracks() videotracksflow\ collect { videotracks > videotracks foreach { track > println("video track id ${track id}") } } getaudiotracks() stateflow\<list\<expmanifestaudiotrack>> retrieves a flow of audio tracks from the experience manifest val audiotracksflow = experienceplaybackservice getaudiotracks() audiotracksflow\ collect { audiotracks > audiotracks foreach { track > println("audio track id ${track id}") } } getglobalaudiotracks() stateflow\<list\<expmanifestglobalaudiotrack>> retrieves a flow of global audio tracks from the experience manifest val globalaudiotracksflow = experienceplaybackservice getglobalaudiotracks() globalaudiotracksflow\ collect { globalaudiotracks > globalaudiotracks foreach { track > println("global audio track id ${track id}") } } getaudiotrackbyid(trackid string?) expmanifestaudiotrack? gets a specific audio track by its id from the experience manifest val audiotrack = experienceplaybackservice getaudiotrackbyid("audiotrackid123") println("audio track name ${audiotrack? name}") getvideotrackbyid(trackid string?) expmanifestvideotrack? gets a specific video track by its id from the experience manifest val videotrack = experienceplaybackservice getvideotrackbyid("videotrackid123") println("video track name ${videotrack? name}") setexpmanifestlistener(expmanifestlistener expmanifestlistener?) sets a listener to observe changes in the experience manifest experienceplaybackservice setexpmanifestlistener(object expmanifestlistener { override fun onmanifestupdated(newmanifest expmanifestdata) { println("manifest has been updated new id ${newmanifest id}") } // implement other required methods }) playback information retrieval getcurrentplaybackdetails() currentplaybackdetails retrieves details about the current playback state val currentplaybackdetails = experienceplaybackservice getcurrentplaybackdetails() println("current playback position ${currentplaybackdetails position}") getexpinfo() currentplaybackdetails? gets extended information about the current experience val expinfo = experienceplaybackservice getexpinfo() expinfo? let { println("experience duration ${it duration}") } getglobalaudiobyid(entityid string?) expmanifestglobalaudiotrack? retrieves a global audio track by its entity id from the experience manifest val globalaudiotrack = experienceplaybackservice getglobalaudiobyid("audioentityid123") globalaudiotrack? let { println("global audio track name ${it name}") } getvideotrackbyentityid(entityid string?) expmanifestvideotrack? retrieves a video track by its entity id from the experience manifest val videotrack = experienceplaybackservice getvideotrackbyentityid("videoentityid123") videotrack? let { println("video track title ${it title}") } listener management addexperiencelistener(playbackexperiencelistener playbackexperiencelistener) adds a listener for playback experience events experienceplaybackservice addexperiencelistener(object playbackexperiencelistener { override fun onplaybackstarted() { println("playback has started ") } override fun onplaybackpaused() { println("playback has been paused ") } // implement other required methods }) addsynclistener(synclistener synclistener) adds a listener for synchronization events experienceplaybackservice addsynclistener(object synclistener { override fun onsyncstarted() { println("synchronization has started ") } override fun onsyncstopped() { println("synchronization has stopped ") } // implement other required methods }) service termination terminateexpplaybackservice() terminates the experience playback service, cleaning up any resources and stopping all ongoing activities ensure you call terminateexpplaybackservice upon exiting your application or when the service is not required to avoid unexpected behavior, crashes, or lag this step is vital for releasing resources and maintaining your app's stability and performance experienceplaybackservice terminateexpplaybackservice() println("experience playback service has been terminated ") this documentation outlines the core functionalities of the experienceplaybackservice interface, enabling developers to effectively manage and control multimedia playback experiences within their applications lifecycle management ondestroy() this function should be called when the ui will close it is used to release resources and stop any ongoing operations override fun ondestroy() { super ondestroy() coresdk ondestroy() } nwexpui nwexpui serves as a customizable interface to gui overlays the communication with the web layer is done using methods to send and receive certain events and states the class described in the section below wraps this functionality if you want to know more about the underlying system and the event system that is used to communicate between the native and web layer, you can find a more thorough explanation in the event system docid\ d58owrhhf 5ibm6a4pc9f chapter of the web sdk the nwexpui alone does not play any content it needs to be rendered above a player or a playback system like the nativewaves core here's an overview of the nwexpui interface nativetowebactions a lazy initialized instance of nativetowebactions interface this instance converts the action type and payload into a javascript function call and executes this javascript in the webview logging is also done to track the javascript function call nativetoweb(actions nativetowebactions) this function takes a nativetowebactions object as a parameter and sends it to the webview if the webview overlay is initialized, it directly sends the actions to webview otherwise, it adds the actions to a waiting list waitinglistedactions to be sent later jsinterfaceactions a lazy initialized instance of jsinterfaceactions this instance provides callbacks for various javascript related operations such as asking for permissions, handling native to web actions, managing core sdk, volume, playback, etc it also handles operations like gui readiness, manual mute, and sync status it also takes care of actions to be taken when the webview overlay is initialized like sending waiting list actions to webview and starting the webview experience volumeobserver a lazily initialized observer that responds to changes in system volume settings, invoking a function to handle volume related actions and updates in the application