1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-03 05:50:32 +00:00

WIP: Inject (a local) NewPlayer into the NewPipe application

This is the basic setup that allows us to inject a NewPlayer instance
into NewPipe. Frankenpipe, rise!
This commit is contained in:
Profpatsch 2024-12-04 15:21:35 +01:00
parent fbafdeb2ca
commit c02fb89359
5 changed files with 89 additions and 0 deletions

View File

@ -199,6 +199,8 @@ dependencies {
implementation libs.teamnewpipe.newpipe.extractor
implementation libs.teamnewpipe.nononsense.filepicker
implementation 'com.github.TeamNewPipe:NewPlayer'
/** Checkstyle **/
checkstyle libs.tools.checkstyle
ktlint libs.tools.ktlint

View File

@ -56,6 +56,8 @@ import androidx.preference.PreferenceManager;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import net.newpipe.newplayer.NewPlayer;
import org.schabi.newpipe.databinding.ActivityMainBinding;
import org.schabi.newpipe.databinding.DrawerHeaderBinding;
import org.schabi.newpipe.databinding.DrawerLayoutBinding;
@ -94,11 +96,19 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.inject.Inject;
import dagger.hilt.android.AndroidEntryPoint;
@AndroidEntryPoint
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@SuppressWarnings("ConstantConditions")
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
@Inject
NewPlayer newPlayer;
private ActivityMainBinding mainBinding;
private DrawerHeaderBinding drawerHeaderBinding;
private DrawerLayoutBinding drawerLayoutBinding;

View File

@ -0,0 +1,66 @@
/* NewPlayer
*
* @author Christian Schabesberger
*
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de>
*
* NewPlayer is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/
package net.newpipe.newplayer.testapp
import android.app.Application
import android.util.Log
import androidx.core.graphics.drawable.IconCompat
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.newpipe.newplayer.NewPlayer
import net.newpipe.newplayer.NewPlayerImpl
import net.newpipe.newplayer.repository.CachingRepository
import net.newpipe.newplayer.repository.PlaceHolderRepository
import net.newpipe.newplayer.repository.PrefetchingRepository
import org.schabi.newpipe.App
import org.schabi.newpipe.MainActivity
import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
object NewPlayerComponent {
@Provides
@Singleton
fun provideNewPlayer(app: Application): NewPlayer {
val player = NewPlayerImpl(
app = app,
repository = PrefetchingRepository(CachingRepository(PlaceHolderRepository())),
notificationIcon = IconCompat.createWithResource(app, net.newpipe.newplayer.R.drawable.new_player_tiny_icon),
playerActivityClass = MainActivity::class.java,
// rescueStreamFault = …
)
if (app is App) {
CoroutineScope(Dispatchers.IO).launch {
while (true) {
player.errorFlow.collect { e ->
Log.e("NewPlayerException", e.stackTraceToString())
}
}
}
}
return player
}
}

View File

@ -17,6 +17,10 @@ buildscript {
}
}
plugins {
id 'com.google.dagger.hilt.android' version '2.52' apply false
}
allprojects {
repositories {
google()

View File

@ -9,3 +9,10 @@ include ':app'
// substitute module('com.github.TeamNewPipe:NewPipeExtractor') using project(':extractor')
// }
//}
includeBuild('../NewPlayer') {
dependencySubstitution {
substitute module('com.github.TeamNewPipe:NewPlayer') using project(':new-player')
}
}