Lumen help

Legacy Integration for IDVIU 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"/>

            
                private void startDnaClient(Entry entry) {
    // Init the player interactor
    PlayerInteractor playerInteractor = new IdviuInteractor(this.mPlayerView);

    // Build and start the DNAClient
    try {
        this.dnaClient = DnaClient.newBuilder()
            .context(getApplicationContext())
            .playerInteractor(playerInteractor)
            .streamrootKey(<String>)
            .latency(latency)
            .start(Uri.parse(entry.getUrl()));
    } catch (Exception e){
        Log.e("Streamroot", e.getLocalizedMessage());
    }
}
            
                dnaClient.getManifestUrl() : <Uri>
            
                import android.os.Looper;
import com.labgency.hss.HSSPlayer;
import com.labgency.hss.views.HSSPlayerView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
import java.util.List;
import io.streamroot.dna.core.PlayerInteractor;
import io.streamroot.dna.core.TimeRange;
import static com.labgency.hss.HSSPlayer.PLAYER_PARAM_MAX_BUFFER_LENGTH;

public class IdviuInteractor implements PlayerInteractor {
    private HSSPlayerView mPlayerView = null;

    public IdviuInteractor(HSSPlayerView mPlayerView) {
        this.mPlayerView = mPlayerView;
    }

    @NotNull
    @Override
    public List<TimeRange> loadedTimeRanges() {
        long currentPosition = this.mPlayerView.getPlayer().getLivePosition();
        long bufferedPosition = currentPosition + this.mPlayerView.getPlayer().getBufferLength();
        return Collections.singletonList(new TimeRange(currentPosition, bufferedPosition));
    }

    @Nullable
    @Override
    public Looper looper() {
        return Looper.getMainLooper();
    }

    @Override
    public long playbackTime() {
        return this.mPlayerView.getPlayer().getPosition();
    }
    @Override
    public double bufferTarget() {
        return this.mPlayerView.getPlayer().getMaxBufferLength();
    }

    @Override
    public void setBufferTarget(double v) {
        this.mPlayerView.getPlayer().setParam("max_buffer_length", String.valueOf(v));
    }
}
            
                import android.util.Log;
import com.labgency.hss.HSSAgent;
import com.labgency.hss.HSSDownload;
import com.labgency.hss.views.HSSPlayerView;
import io.streamroot.dna.core.BandwidthListener;

public class IdviuBandwithMeter implements BandwidthListener {
    private HSSPlayerView mPlayerView = null;

    public IdviuBandwithMeter(HSSPlayerView mPlayerView) {
        this.mPlayerView = mPlayerView;
    }

    @Override
    public void onBandwidthChange(long bandwith) {
        long dldId = HSSAgent.getDownloadManager().addDownload(mPlayerView.getPlaylist().items().get(0).url(), true);
        HSSDownload download = HSSAgent.getDownloadManager().getDownload(dldId);
        if (download != null){
            download.setMaxVideoBitrate(bandwith);
            HSSAgent.getDownloadManager().unpauseDownload(dldId);
        }
    }
}
            
                // Init the player bandwidth listener
BandwidthListener bandwidthListener = new IdviuBandwithMeter(this.mPlayerView);

// Build and start the DNAClient
try {
    this.dnaClient = DnaClient.newBuilder()
        .context(getApplicationContext())
        .playerInteractor(playerInteractor)
        ...
        
        .bandwidthListener(bandwidthListener)

        ...
        .start(Uri.parse(entry.getUrl()));
    } catch (Exception e){
        Log.e("Streamroot", e.getLocalizedMessage());
    }
}
            
                import android.media.MediaPlayer;
import com.labgency.hss.views.HSSPlayerView;
import com.labgency.hss.views.HSSPlayerViewListeners;
import io.streamroot.dna.core.PlaybackState;
import io.streamroot.dna.core.QosModule;
final class IdviuQoSModule extends QosModule implements
        MediaPlayer.OnCompletionListener,
        MediaPlayer.OnErrorListener,
        MediaPlayer.OnInfoListener, HSSPlayerViewListeners.OnTrackSelectionListener, MediaPlayer.OnBufferingUpdateListener {
    private HSSPlayerView mPlayerView = null;

    IdviuQoSModule(HSSPlayerView mPlayerView) {
        super();
        this.mPlayerView = mPlayerView;
        this.mPlayerView.setOnCompletionListener(this);
        this.mPlayerView.setOnErrorListener(this);
        this.mPlayerView.setOnInfoListener(this);
        this.mPlayerView.setOnTrackSelectionChangeListener(this);
    }

    void setBufferStateListener() {
        if (this.mPlayerView.getPlayer() != null) {
            this.mPlayerView.getPlayer().setOnBufferingUpdateListener(this);
        }
    }

    @Override
    public boolean onError(MediaPlayer mp, int what, int extra) {
        playbackErrorOccurred();
        return false;
    }

    @Override
    public boolean onInfo(MediaPlayer mp, int what, int extra) {
        if (mp.isPlaying()) {
            playbackStateChange(PlaybackState.PLAYING);
        } else {
            playbackStateChange(PlaybackState.PAUSING);
        }
        return true;
    }

    @Override
    public void onCompletion(MediaPlayer mp) {
        playbackStateChange(PlaybackState.ENDED);
    }

    @Override
    public boolean onAudioTrackSelectorRequested() {
        return false;
    }

    @Override
    public boolean onCaptionsTrackSelectorRequested() {
        trackSwitchOccurred();
        return false;
    }

    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        playbackStateChange(PlaybackState.BUFFERING);
    }
}
            
                // Init qosModule (optional)
QosModule qosModule = new IdviuQoSModule(this.mPlayerView);

// Build and start the DNAClient
try {
    this.dnaClient = DnaClient.newBuilder()
        .context(getApplicationContext())
        .playerInteractor(playerInteractor)
        ...
        
        .qosModule(qosModule)

        ...
        .start(Uri.parse(entry.getUrl()));
    } catch (Exception e){
        Log.e("Streamroot", e.getLocalizedMessage());
    }
}
            
                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>