Lumen help

Legacy Integration for NexPlayer on Android

Project setup

                repositories {
    maven {
        url 'https://sdk.streamroot.io/android'
    }
}
            
                implementation 'io.streamroot.dna:dna-core:3.23.0'
            
                android {
// Configure only for each module that uses Java 8
// language features (either in its source code or
// through dependencies).
compileOptions {
      sourceCompatibility JavaVersion.VERSION_1_8
      targetCompatibility JavaVersion.VERSION_1_8
  }
}

            

Integrate Lumen SDK

                <meta-data
        android:name="io.streamroot.dna.StreamrootKey"
        android:value="streamrootKey"/>

            
                DnaClient dnaClient = DnaClient.newBuilder()
    .context(<Context>)
    .playerInteractor(<PlayerInteractor>)    
    .latency(<Integer>)
    .start(<Uri>);

            
                import com.nexstreaming.nexplayerengine.NexPlayer;
import io.streamroot.dna.core.PlayerInteractor;
import io.streamroot.dna.core.TimeRange;

import java.util.Collections;
import java.util.List;

import static java.util.Collections.emptyList;

public class NexPlayerInteractor implements PlayerInteractor {
    private final NexPlayer mNexPlayer;

    public NexPlayerInteractor(NexPlayer mNexPlayer) {
        this.mNexPlayer = mNexPlayer;
    }

    @Override
    public long playbackTime() {
        return mNexPlayer.getCurrentPosition();
    }

    @Override
    public List<TimeRange> loadedTimeRanges() {
        int state = mNexPlayer.getState();
        if ( state == NexPlayer.NEXPLAYER_STATE_PLAY
                || state == NexPlayer.NEXPLAYER_STATE_PAUSE ) {
            int bufferDuration = mNexPlayer.getBufferInfo(NexPlayer.MEDIA_STREAM_TYPE_VIDEO, NexPlayer.NEXPLAYER_BUFINFO_INDEX_DURATION);
            int currentCts = mNexPlayer.getCurrentPosition();
            return Collections.singletonList(new TimeRange(currentCts, bufferDuration));
        }

        return emptyList();
    }
}
            
                #ExoPlayer
-keep class com.google.android.exoplayer2.** { *; }
-keep interface com.google.android.exoplayer2.** { *; }
            
                import com.nexstreaming.nexplayerengine.NexABRController;
import io.streamroot.dna.core.BandwidthListener;

public class NexPlayerBandwidthListener implements BandwidthListener {
private final NexABRController arbController;

    NexPlayerBandwidthListener(NexABRController arbController) {
        this.arbController = arbController;
    }

   @Override
   public void onBandwidthChange(long estimatedBandwidth) {
        arbController.setTargetBandWidth((int) estimatedBandwidth,
               NexABRController.SegmentOption.DEFAULT,
               NexABRController.TargetOption.DEFAULT);
   }
}
            
                DnaClient dnaClient = DnaClient.newBuilder()
     .context(<Context>)
     .playerInteractor(<PlayerInteractor>)
     ...

     .bandwidthListener(<BandwidthListener>)

     ...
     .start(<String>);
            
                import com.nexstreaming.nexplayerengine.NexEventReceiver;
import com.nexstreaming.nexplayerengine.NexPlayer;
import io.streamroot.dna.core.PlaybackState;
import io.streamroot.dna.core.QosModule;

import static com.nexstreaming.nexplayerengine.NexPlayer.*;

public class NexPlayerQosModule extends QosModule {

    public NexPlayerQosModule(NexPlayer mNexPlayer) {
        mNexPlayer.addEventReceiver(eventReceiver);
    }

    private final NexEventReceiver eventReceiver = new NexEventReceiver() {
        @Override
        public void onEndOfContent(NexPlayer mp) {
            playbackStateChange(PlaybackState.ENDED);
        }

        @Override
        public void onBufferingBegin(NexPlayer mp) {
            playbackStateChange(PlaybackState.BUFFERING);
        }

        @Override
        public void onAsyncCmdComplete(NexPlayer mp, int command, int result, int param1, int param2) {
            switch (command) {
                case NEXPLAYER_ASYNC_CMD_START_STREAMING:
                case NEXPLAYER_ASYNC_CMD_RESUME:
                    playbackStateChange(PlaybackState.PLAYING);
                    break;
                case NEXPLAYER_ASYNC_CMD_STOP:
                    playbackStateChange(PlaybackState.ENDED);
                    break;
                case NEXPLAYER_ASYNC_CMD_PAUSE:
                    playbackStateChange(PlaybackState.PAUSING);
                    break;
                case NEXPLAYER_ASYNC_CMD_SEEK:
                    playbackStateChange(PlaybackState.SEEKING);
                    break;
            }
        }

        @Override
        public void onStatusReport(NexPlayer mp, int msg, int param1) {
            if (msg == NEXPLAYER_STATUS_REPORT_TRACK_CHANGED) {
                trackSwitchOccurred();
            }
        }

        @Override
        public void onError(NexPlayer mp, NexPlayer.NexErrorCode errorcode) {
            playbackErrorOccurred();
        }
    };

}
            
                DnaClient dnaClient = DnaClient.newBuilder()
     .context(<Context>)
     .playerInteractor(<PlayerInteractor>)
     ...

     .qosModule(NexPlayerQosModule(<NexPlayer>))

     ...
     .start(<String>);
            
                dnaClient.close();
            
                <?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application
        ...
        android:usesCleartextTraffic="true">
        ...
    </application>
</manifest>
            
                <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
    </domain-config>
</network-security-config>
            
                <?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <application
        ...
        android:networkSecurityConfig="@xml/network_security_config">
        ...
    </application>
</manifest>