Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to keep display on when fullscreen #4

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class BlueskyVideoModule : Module() {
view.toggleMuted()
}

AsyncFunction("enterFullscreen") { view: BlueskyVideoView ->
view.enterFullscreen()
AsyncFunction("enterFullscreen") { view: BlueskyVideoView, keepDisplayOn: Boolean ->
view.enterFullscreen(keepDisplayOn)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class BlueskyVideoView(

// Fullscreen handling

fun enterFullscreen() {
fun enterFullscreen(keepDisplayOn: Boolean) {
val currentActivity = this.appContext.currentActivity ?: return

this.enteredFullscreenMuteState = this.isMuted
Expand All @@ -246,6 +246,7 @@ class BlueskyVideoView(

// create the intent and give it a view
val intent = Intent(context, FullscreenActivity::class.java)
intent.putExtra("keepDisplayOn", keepDisplayOn)
FullscreenActivity.asscVideoView = WeakReference(this)

// fire the fullscreen event and launch the intent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class FullscreenActivity : AppCompatActivity() {
WindowManager.LayoutParams.FLAG_FULLSCREEN,
)

val keepDisplayOn = this.getIntent().getBooleanExtra("keepDisplayOn", false)

if (keepDisplayOn) {
this.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

// Update the player viewz
val playerView =
PlayerView(this).apply {
Expand Down
26 changes: 20 additions & 6 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
Platform,
Pressable,
SafeAreaView,
View
View,
Text,
Switch,
SwitchChangeEvent
} from 'react-native'

import {SAMPLE_VIDEOS} from './sampleVideos'
Expand All @@ -17,12 +20,22 @@ export default function App() {
return [...SAMPLE_VIDEOS, ...SAMPLE_VIDEOS]
}, [])

const renderItem = React.useCallback(({item}: ListRenderItemInfo<string>) => {
return <Player url={item} />
}, [])
const [fullscreenKeepDisplayOn, setFullscreenKeepDisplayOn] = React.useState<boolean>(false);
const toggleFullscreenKeepDisplayOn = React.useCallback((event: SwitchChangeEvent) => {
setFullscreenKeepDisplayOn(v => !v);
}, [setFullscreenKeepDisplayOn]);

const renderItem = React.useCallback(({item, index}: ListRenderItemInfo<string>) => {
return <Player url={item} num={index + 1} fullscreenKeepDisplayOn={fullscreenKeepDisplayOn} />
}, [fullscreenKeepDisplayOn])

return (
<SafeAreaView style={{flex: 1}}>
<Text style={{ fontWeight: 'bold' }}>Options</Text>
<View style={{ flexDirection: 'row' }}>
<Text>Keep display on when fullscreen</Text>
<Switch onChange={toggleFullscreenKeepDisplayOn} value={fullscreenKeepDisplayOn} />
</View>
<View style={{flex: 1}}>
<FlatList
data={data}
Expand All @@ -38,18 +51,19 @@ export default function App() {
)
}

function Player({url}: {url: string}) {
function Player({url, num, fullscreenKeepDisplayOn}: {url: string, num: number, fullscreenKeepDisplayOn: boolean}) {
const ref = React.useRef<BlueskyVideoView>(null)

const onPress = () => {
console.log('press')
ref.current?.enterFullscreen()
ref.current?.enterFullscreen(fullscreenKeepDisplayOn)
}

return (
<Pressable
style={{backgroundColor: 'blue', height: 300}}
onPress={Platform.OS === 'ios' ? onPress : undefined}>
<Text>Video: {num}</Text>
<BlueskyVideoView
url={url}
autoplay
Expand Down
4 changes: 2 additions & 2 deletions ios/BlueskyVideoModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public class BlueskyVideoModule: Module {
view.toggleMuted()
}

AsyncFunction("enterFullscreen") { (view: VideoView) in
view.enterFullscreen()
AsyncFunction("enterFullscreen") { (view: VideoView, keepDisplayOn: Bool) in
view.enterFullscreen(keepDisplayOn)
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion ios/VideoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class VideoView: ExpoView, AVPlayerViewControllerDelegate {
private let onError = EventDispatcher()

private var enteredFullScreenMuted = true
private var enteredFullScreenWithIdleTimerDisabled = false
private var ignoreAutoplay = false
private var isDestroyed = true

Expand Down Expand Up @@ -274,6 +275,9 @@ class VideoView: ExpoView, AVPlayerViewControllerDelegate {
self.mute()
}
self.play()
if !self.enteredFullScreenWithIdleTimerDisabled {
UIApplication.shared.isIdleTimerDisabled = false
}
}
}

Expand Down Expand Up @@ -345,7 +349,7 @@ class VideoView: ExpoView, AVPlayerViewControllerDelegate {
}
}

func enterFullscreen() {
func enterFullscreen(keepDisplayOn: Bool) {
guard let pViewController = self.pViewController,
!isFullscreen else {
return
Expand All @@ -359,6 +363,10 @@ class VideoView: ExpoView, AVPlayerViewControllerDelegate {
self.enteredFullScreenMuted = self.player?.isMuted ?? true
self.unmute()
self.isFullscreen = true
self.enteredFullScreenWithIdleTimerDisabled = UIApplication.shared.isIdleTimerDisabled
if keepDisplayOn {
UIApplication.shared.isIdleTimerDisabled = true
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@haileyok/bluesky-video",
"version": "0.1.10",
"version": "0.2.0",
"description": "A video player library for Bluesky",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/BlueskyVideoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class BlueskyVideoView extends React.Component<BlueskyVideoViewProps> {
this.ref.current?.toggleMuted()
}

enterFullscreen = () => {
this.ref.current?.enterFullscreen()
enterFullscreen = (keepDisplayOn?: boolean) => {
this.ref.current?.enterFullscreen(keepDisplayOn ?? false)
}

render() {
Expand Down