Skip to content

Instantly share code, notes, and snippets.

View Oleur's full-sized avatar
👨‍💻
Doing stuff with the droid!

Julien Salvi Oleur

👨‍💻
Doing stuff with the droid!
View GitHub Profile
@Oleur
Oleur / unityPlayer.cs
Last active February 2, 2024 00:13
Get current Android activity and init an Android object from Unity
AndroidJavaObject localMediaPlayer = null;
using (AndroidJavaClass javaUnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
using (currentActivity = javaUnityPlayer.GetStatic<AndroidJavaObject>("currentActivity"))
{
localMediaPlayer = new AndroidJavaObject("my/plugin/vr/ExoPlayerBridge", currentActivity);
if (localMediaPlayer != null)
{
@Oleur
Oleur / jni_call_unity.cs
Last active October 13, 2016 07:50
JNI Call from Unity
// Can't use AndroidJavaObject.Call() with a jobject, must use low level interface
IntPtr setSimplePlayerID = AndroidJNI.GetMethodID(localMediaPlayer.GetRawClass(), "setSurface", "(Landroid/view/Surface;)V");
jvalue[] parms = new jvalue[1];
parms[0] = new jvalue();
parms[0].l = _androidSurface; // Android Surface reference as an IntPtr
AndroidJNI.CallVoidMethod(localMediaPlayer.GetRawObject(), setSimplePlayerID, parms);
@Oleur
Oleur / GvrAudioProcessor.java
Created April 20, 2017 08:54
GvrAudioProcessor with mono audio channel
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Oleur
Oleur / add_view_container_ktx.kt
Created July 31, 2018 08:15
Add views to a container using KTX library
// Add similar movies to the container
movies.filter { it.hasTrailers }.forEach {
nextTrailersContainer += NextTrailerView(this).apply {
setCallback(this@CinemurPlayerActivity)
setTrailer(it)
}
}
@Oleur
Oleur / ExoPlayerDataSource.java
Last active November 22, 2020 16:03
ExoPlayer DataSource and DataSource Factory
public interface DataSource extends DataReader {
interface Factory {
DataSource createDataSource();
}
void addTransferListener(TransferListener transferListener);
long open(DataSpec dataSpec) throws IOException;
class SmbDataSourceFactory(private val fileUrl: String) : DataSource.Factory {
override fun createDataSource(): DataSource {
val dataSpec = DataSpec(Uri.parse(fileUrl))
return SmbDataSource(dataSpec)
}
}
class SmbDataSource(private val dataSpec: DataSpec) : BaseDataSource(/* isNetwork= */ true) {
private val userName: String
private val password: String
private val hostName: String
private val shareName: String
private val path: String
init {
// Get user credentials
class SmbDataSource(private val dataSpec: DataSpec) : BaseDataSource(/* isNetwork= */ true) {
private var smbClient: SMBClient? = null
private var inputStream: InputStream? = null
private var bytesRemaining: Long
private var opened: Boolean
@Throws(IOException::class)
override fun open(): Long {
try {
class SmbDataSource(private val dataSpec: DataSpec) : BaseDataSource(/* isNetwork= */ true) {
private var bytesRemaining: Long
@Throws(IOException::class)
override fun read(buffer: ByteArray, offset: Int, readLength) {
if (readLength == 0) {
return 0
} else if (bytesRemaining == 0) {
return C.RESULT_END_OF_INPUT
private fun buildMediaSource(uri: Uri, drmSessionManager: DrmSessionManager<FrameworkMediaCrypto>): MediaSource? {
when (val type = PlayerUtils.inferContentType(videoUrl)) {
...
C.TYPE_OTHER -> {
return if (videoUrl.isSmb()) {
ProgressiveMediaSource.Factory(SmbDataSourceFactory(videoUrl))
.setDrmSessionManager(drmSessionManager)
.createMediaSource(uri)
} else {
ProgressiveMediaSource.Factory(mediaDataSourceFactory)