Skip to content

Commit

Permalink
add first steps to integrate NewPlayer into your project
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 24, 2024
1 parent daa0ff0 commit af8544e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .vscode/ltex.dictionary.en-US.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NewPlayer
JitPack
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,41 @@ Main menu
</tr>
</table>

### How does NewPlayer work
### Getting started

NewPlayer uses [MVVM](https://www.geeksforgeeks.org/mvvm-model-view-viewmodel-architecture-pattern-in-android/) architecture design pattern.
1. **Add NewPlayer to your project**

![Immage showing NewPlayer's architecture](/misc/newplayer_architecture.svg)
You can do this by adding the [JitPack](https://jitpack.io/) repository:
```
implementation 'com.github.TeamNewPipe:NewPlayer:master-SNAPSHOT'
```

TODO: Documentation
2. **Modify your Activity in the `AndroidManifest.xml`**
- Add `android:supportsPictureInPicture="true"` to the `<activity>` tag of the activity that will hold the [NewPlayerUI](https://github.com/TeamNewPipe/NewPlayer/blob/master/new-player/src/main/java/net/newpipe/newplayer/ui/NewPlayerUI.kt)
- 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](https://github.com/TeamNewPipe/NewPlayer/blob/72c14d39822b96420f5c71bb559b47f39dc9ed90/test-app/src/main/java/net/newpipe/newplayer/testapp/MainActivity.kt#L173-L198) 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](https://developer.android.com/reference/kotlin/androidx/compose/material3/adaptive/package-summary) framework to handle screen rotation foo.

3. **Install NewPlayer in your Activity's layout**

NewPlayer can be used in a [compose](https://developer.android.com/compose) as well as the classic views environment.
- **Use NewPlayer with Compose**

You can add NewPlayer in a compose environment by using the [`NewPlayerUI`](https://github.com/TeamNewPipe/NewPlayer/blob/72c14d39822b96420f5c71bb559b47f39dc9ed90/new-player/src/main/java/net/newpipe/newplayer/ui/NewPlayerUI.kt#L59) composable for now we will add it with a dummy view model (later more about that):
```kotlin
NewPlayerUI(NewPlayerViewModelDummy())
```
- **Use NewPlayer with views**

For a views environment (and for compatibility with NewPipe before its UI refactoring), NewPlayer provides a [`NewPlayerView`]() TODO
4. **Install NewPlayer in your code**

### How to use NewPlayer
NewPlayer requires [Hilt](https://developer.android.com/training/dependency-injection/hilt-android) for dependency injection.

You can use NewPlayer in you project by adding its [JitPack](https://jitpack.io/) repository to your dependencies:
```
implementation 'com.github.TeamNewPipe:NewPlayer:master-SNAPSHOT'
```


### How does NewPlayer work

NewPlayer uses [MVVM](https://www.geeksforgeeks.org/mvvm-model-view-viewmodel-architecture-pattern-in-android/) architecture design pattern.

![Immage showing NewPlayer's architecture](/misc/newplayer_architecture.svg)
TODO: Documentation
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import net.newpipe.newplayer.ui.NewPlayerView
import net.newpipe.newplayer.uiModel.InternalNewPlayerViewModel
import net.newpipe.newplayer.uiModel.NewPlayerViewModel
import net.newpipe.newplayer.uiModel.NewPlayerUIState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>.
*/

package net.newpipe.newplayer
package net.newpipe.newplayer.ui

import android.content.Context
import android.util.AttributeSet
Expand All @@ -27,9 +27,9 @@ import android.widget.FrameLayout
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import dagger.hilt.android.AndroidEntryPoint
import net.newpipe.newplayer.R
import net.newpipe.newplayer.uiModel.InternalNewPlayerViewModel
import net.newpipe.newplayer.uiModel.NewPlayerViewModel
import net.newpipe.newplayer.ui.NewPlayerUI
import net.newpipe.newplayer.ui.theme.VideoPlayerTheme
import net.newpipe.newplayer.data.NewPlayerException

Expand Down

0 comments on commit af8544e

Please sign in to comment.