Icon by Jaime López
NewPlayer is a media framework, which is independent of NewPipe itself. I decided to make it independent, because one of the big issues we have with the current player is that it is deeply integrated into NewPipe. Therefore, I wanted to make NewPlayer a separate module in order to enforce that the interface between NewPipe and the player is only as big as necessary. This also has the advantage that NewPlayer can be used independently of NewPipe itself, which means it can be used in other apps too.
- It is a module, separate from NewPipe and can be used as an independent player framework
- It is based on the Media3 library
- Its UI is created with Jetpack Compose
- It's fully written in Kotlin
- Its UI resembles the UI of the current NewPipe player, but improves it
- The UI uses Material You theming
- It follows an MVVM architecture
- It is GPLv3 licensed
- It uses Hilt dependency injection
Embedded Screen in test App |
Fullscreen |
Audio frontend |
Audio frontend landscape |
Playlist screen |
Chapter screen |
Picture in Picture |
Volume indicator |
Main menu |
-
Add NewPlayer to your project
You can do this by adding the JitPack repository:
implementation 'com.github.TeamNewPipe:NewPlayer:master-SNAPSHOT'
-
Modify your Activity in the
AndroidManifest.xml
- Add
android:supportsPictureInPicture="true"
to the<activity>
tag of the activity that will hold the NewPlayerUI - Also add
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
to the<activity>
tag. This will ensure a smooth transition from and to PiP mode. However, be aware that when you do this, a screen rotation or size change does not trigger an activity reconfiguration. You may have to trigger this by yourself. See this code from the text app if you want to know how you could achieve this. However, bear in mind that if you use compose you might not need a screen reconfiguration at all. There just use androidx.adaptive framework to handle screen rotation foo.
- Add
-
Install NewPlayer in your Activity's layout
NewPlayer can be used in a compose as well as the classic views environment.
-
Use NewPlayer with Compose
You can add NewPlayer in a compose environment by using the
NewPlayerUI
composable for now we will add it with a dummy view model (later more about that):NewPlayerUI(NewPlayerViewModelDummy())
-
Use NewPlayer with views
For a views environment (and for compatibility with NewPipe before its UI refactoring), NewPlayer provides a
NewPlayerView
. This acts as a simple wrapper for theNewPlayerUI
composable.In order to use it simply put it into the layout of the activity/fragment that should host NewPlayer. You can put multiple instances of
NewPlayerView
into your layoutNewPlayerViewModel
. You should only have one instance ofNewPlayerView
in your layout.You can find an exmapple of how to use
NewPlayerView
in the test-app (If there are still two versions ofNewPlayerView
in the test-app's layout: Dear NewPlayer devs, please make it one asap.)Remember to also give the
NewPlayerView
an instance ofNewPlayerViewModel
in theonCreate()
function of your activity/fragment.
-
-
Install NewPlayer in your code
NewPlayer requires Hilt for dependency injection. Therefore, you must create an instance of the NewPlayer object through a Component that must install the NewPlayer instance in the
Application
instance. The NewPlayer instance must live for as long as the app lives. An example of how to do this can be found again in thetest-app
.In order to use NewPlayer, the NewPlayer object needs an instance of the
MediaRepository
. TheMediaRepository
is the primary way that NewPlayer can access data and request the information it needs to operate. In other words you provide NewPlayer with the information it needs through theMediaRepository
. Because of this you will have to implement this yourself and provide it toNewPlayer
. For the sake of simplicity however for now you can give the NewPlayer object thePlaceHolderRepository
. This repository implementation does nothing but at least allows you to continue installing NewPlayer without a functioning Repository yet. -
Install NewPlayer in the NewPlayerViewModel
Eventually you will have to put install the NewPlayer instance in the
NewPlayerViewModel
instance in the Activity that hosts the viewmodel. This wayNewPlayer
can actually talk to your UI. You can do this by simply setting the viewmodel's NewPlayer:myNewPlayerViewModel.newPlayer = myNewPlayer
. -
Give NewPlayer access to your media
You can do this by implementing your own
MediaRepository
. You can find more information about theMediaRepository
inside itscode documentation
. You can also find a test implementation of it in the test-app. -
Do advanced things Like applying caching and prefetching to your media repository using the meta
MediaRepository
implementations, or perform error handling and error recovering. TOOD: Write the documentation for this
NewPlayer uses MVVM architecture design pattern.
TODO
TODO
TODO
TODO: Documentation