Italian Estendere un video full screen

ken87

Active Member
Licensed User
Longtime User
Sto creando un gioco da tavolo una cosa tipo monopoli dove hai le pedine che si muovono nelle celle , vorrei avere un sfondo animato con un video , quello che non capisco come si estende un video full screen ? per un immagine tutto ok ma per il video resta piccolo al lato , mi aiutate in b4x o b4a
 

ken87

Active Member
Licensed User
Longtime User
Come si vede il video è la scacchiera e poi rimane la parte nera perchè non si estende in larghezza , non so come fare
metodo per estendere il video:
rivate Sub CreaSfondoFullSeServe
    If videoPlayer.IsInitialized Then Return

    ' Copia il file (se non esiste già)
    If File.Exists(File.DirInternal, VIDEO_FILENAME) = False Then
        Try
            File.Copy(File.DirAssets, VIDEO_FILENAME, File.DirInternal, VIDEO_FILENAME)
            Log("Video copiato con successo")
        Catch
            Log("Errore copia file: " & LastException.Message)
            Return
        End Try
    End If

    videoPlayer.Initialize("videoPlayer")
    videoPlayer.Visible = True

    Root.AddView(videoPlayer, 0, 0, Root.Width, Root.Height)
    videoPlayer.SendToBack

    Try
        videoPlayer.LoadVideo(File.DirInternal, VIDEO_FILENAME)
        Log("Caricamento video avviato da: " & File.DirInternal)
    Catch
        Log("Errore caricamento: " & LastException.Message)
    End Try

    ' Fallback immediato (anche se non è ancora pronto)
    ApplicaCenterCrop
End Sub

Ho provato con questo ma nulla
 

Attachments

  • vid1.png
    vid1.png
    500.4 KB · Views: 77

Sagenut

Expert
Licensed User
Longtime User
Utilizzi ExoPlayer per il video di fondo?

*** EDIT ***
No, mi pare sia solo per B4A
 

Sagenut

Expert
Licensed User
Longtime User
Se puoi posta un esempio minimo con il videoplayer e un qualche layout sopra.
Così almeno lavoriamo sulla base su cui sei arrivato ora.
 

LucaMs

Expert
Licensed User
Longtime User
Sarà mica a causa di ciò che mi fa inc..... da una vita, ovvero il rapporto base/altezza dei display, che i produttori non standardizzano? :mad:
Voglio dire che magari il tuo smartphone ha quel valore più alto del video, ovvero la base è più larga in proporzione all'altezza, rispetto al video.
(Numeri a caso) Se il video fosse nel formato 16:9 e il tuo display fosse 17:9, 18:9, ... se dovessi avere il video a tutto schermo, verrebbe distorto in larghezza.
 

ken87

Active Member
Licensed User
Longtime User
Codice Video full:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=%PROJECT_NAME%.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
  
    Private videoPlayer As VideoView
    Private VideoReady As Boolean = False
    Private Const VIDEO_FILENAME As String = "Sfondo_animato.mp4"
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.



Private Sub CreaSfondoFullSeServe
    If videoPlayer.IsInitialized Then Return

    ' Copia il file (se non esiste già)
    If File.Exists(File.DirInternal, VIDEO_FILENAME) = False Then
        Try
            File.Copy(File.DirAssets, VIDEO_FILENAME, File.DirInternal, VIDEO_FILENAME)
            Log("Video copiato con successo")
        Catch
            Log("Errore copia file: " & LastException.Message)
            Return
        End Try
    End If

    videoPlayer.Initialize("videoPlayer")
    videoPlayer.Visible = True

    Root.AddView(videoPlayer, 0, 0, Root.Width, Root.Height)
    videoPlayer.SendToBack

    Try
        videoPlayer.LoadVideo(File.DirInternal, VIDEO_FILENAME)
        Log("Caricamento video avviato da: " & File.DirInternal)
    Catch
        Log("Errore caricamento: " & LastException.Message)
    End Try

    ' Fallback immediato (anche se non è ancora pronto)
'    ApplicaCenterCrop
End Sub



Private Sub videoPlayer_Ready
    VideoReady = True
    Try
        videoPlayer.Play
    Catch
        Log("Errore videoPlayer_Ready: " & LastException.Message)
    End Try

    ' Crop reale

End Sub



Private Sub videoPlayer_Prepared
    VideoReady = True
    Try
        videoPlayer.Play
    Catch
        Log("Errore videoPlayer_Prepared: " & LastException.Message)
    End Try

  
End Sub



Private Sub ApplicaCenterCrop
    If videoPlayer.IsInitialized = False Then Return
    If Root.IsInitialized = False Then Return

    'Wrap dell'istanza VideoView (NON static)
    Dim jo As JavaObject = videoPlayer

    Dim vwPx As Int = jo.RunMethod("getVideoWidth", Null)
    Dim vhPx As Int = jo.RunMethod("getVideoHeight", Null)
    If vwPx <= 0 Or vhPx <= 0 Then Return

    'px -> dip
    Dim scale As Float = GetDeviceLayoutValues.Scale
    Dim vw As Float = vwPx / scale
    Dim vh As Float = vhPx / scale

    Dim rw As Float = Root.Width
    Dim rh As Float = Root.Height

    'Cover: riempi tutto (taglia il minimo)
    Dim s As Float = Max(rw / vw, rh / vh)
    Dim newW As Float = vw * s
    Dim newH As Float = vh * s

    Dim left As Float = (rw - newW) / 2
    Dim top As Float  = (rh - newH) / 2

    videoPlayer.SetLayoutAnimated(0, left, top, newW, newH)
    videoPlayer.SendToBack
End Sub




Private Sub B4XPage_Appear
    CreaSfondoFullSeServe
    If VideoReady Then ApplicaCenterCrop
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If videoPlayer.IsInitialized Then
        'fallback fullscreen
        videoPlayer.SetLayoutAnimated(0, 0, 0, Width, Height)
        If VideoReady Then ApplicaCenterCrop
    End If
End Sub


Private Sub Button1_Click
'    xui.MsgboxAsync("Hello world!", "B4X")
End Sub

Con Orientamento in questo modo #SupportedOrientations: landscape non riesco a vederlo a full screen ma solo tutto a un lato, Non posso mettere il tutto in quanto dice file troppo grandi anche in rar , Ho i seguenti problemi in
1) Video voglio che parti subito ,
2) Che vada in loop ,
3) Che si visualizzi a schermo intero,
4 ) La barra play non la voglio
 

Attachments

  • mainpage.bal
    806 bytes · Views: 57
  • WhatsApp Image 2026-02-05 at 09.30.05.jpeg
    WhatsApp Image 2026-02-05 at 09.30.05.jpeg
    45.9 KB · Views: 69
Last edited:

ken87

Active Member
Licensed User
Longtime User
Ho cambiato libreria ecco il codice
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private SimpleExoPlayerView1 As SimpleExoPlayerView
    Private Player As SimpleExoPlayer

    Private tLoop As Timer
    Private LastPos As Long = 0
    Private WasPlaying As Boolean = False
End Sub

Public Sub Initialize
End Sub

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")

    Player.Initialize("player")
    SimpleExoPlayerView1.Player = Player

    ' Nascondi controlli (se supportato)
    NascondiControlli_NoCrash

    Dim path As String = File.Combine(File.DirInternal, "Sfondo_animato.mp4")
    Player.Prepare(Player.CreateUriSource(path))

    ' Prova loop nativo ExoPlayer
    LoopInfinito_NoCrash

    ' Fallback loop (se repeat mode non viene applicato)
    tLoop.Initialize("tLoop", 500)
    tLoop.Enabled = True

    ' Play
    Player.Play

    ' Prova zoom fullscreen (se supportato)
    ProvaResizeModeZoom_NoCrash
End Sub

Private Sub B4XPage_Resize (Width As Int, Height As Int)
    If SimpleExoPlayerView1.IsInitialized Then
        SimpleExoPlayerView1.SetLayoutAnimated(0, 0, 0, Width, Height)
    End If
End Sub

' =========================
' PAUSA / RIPRESA DA BACKGROUND
' =========================
Private Sub B4XPage_Disappear
    ' salvo posizione e metto in pausa
    WasPlaying = True ' lo usiamo come "voglio riprendere"
    LastPos = GetCurrentPosition_NoCrash
    Try
        Player.Pause
    Catch
    End Try
End Sub

Private Sub B4XPage_Appear
    ' riprende da dove era
    If WasPlaying Then
        SeekTo_NoCrash(LastPos)
        Try
            Player.Play
        Catch
        End Try
    End If
End Sub

' =========================
' LOOP FALLBACK (se RepeatMode non funziona)
' =========================
Private Sub tLoop_Tick
    Dim dur As Long = GetDuration_NoCrash
    Dim pos As Long = GetCurrentPosition_NoCrash
    If dur > 0 And pos >= dur - 250 Then
        ' siamo alla fine -> riparti
        SeekTo_NoCrash(0)
        Try
            Player.Play
        Catch
        End Try
    End If
End Sub

' =========================
' HELPERS SICURI (No crash)
' =========================
Private Sub NascondiControlli_NoCrash
    Try
        Dim jo As JavaObject = SimpleExoPlayerView1
        jo.RunMethod("setUseController", Array(False))
    Catch
        Log("setUseController non supportato.")
    End Try
End Sub

Private Sub LoopInfinito_NoCrash
    Try
        Dim jPlayer As JavaObject = Player
        ' 2 = REPEAT_MODE_ALL
        jPlayer.RunMethod("setRepeatMode", Array(2))
    Catch
        Log("RepeatMode non supportato (userò fallback timer).")
    End Try
End Sub

Private Sub ProvaResizeModeZoom_NoCrash
    Try
        Dim jo As JavaObject = SimpleExoPlayerView1
        ' 4 = ZOOM
        jo.RunMethod("setResizeMode", Array(4))
    Catch
        Log("ResizeMode ZOOM non supportato.")
    End Try
End Sub

Private Sub GetCurrentPosition_NoCrash As Long
    Try
        Dim jPlayer As JavaObject = Player
        Return jPlayer.RunMethod("getCurrentPosition", Null)
    Catch
        Return 0
    End Try
End Sub

Private Sub GetDuration_NoCrash As Long
    Try
        Dim jPlayer As JavaObject = Player
        Return jPlayer.RunMethod("getDuration", Null)
    Catch
        Return 0
    End Try
End Sub

Private Sub SeekTo_NoCrash(ms As Long)
    If ms < 0 Then ms = 0
    Try
        Dim jPlayer As JavaObject = Player
        jPlayer.RunMethod("seekTo", Array(ms))
    Catch
    End Try
End Sub
ho tolto la barra il problema e che il video non va in loop , poi vorrei che si bloccasse se app va in pausa e riprende dal ritorno in pausa
 

Sagenut

Expert
Licensed User
Longtime User
Sarebbe davvero utile, per non dire necessario, che tu riuscissi a condividere il progetto intero.
Avevi scritto che era troppo grande, probabilmente causa il file video.
Carica lo zip su Google drive o drop box o servizi simili e condividi il link per scaricarlo.
Perché altrimenti diventa un lavoro dover ricreare un progetto che sia simile al tuo, poi magari con il video che usiamo noi funziona e con il tuo no.....
Avendo invece esattamente il tuo materiale è tutto più facile e veloce e la verifica è effettivamente sul tuo progetto.
 

ken87

Active Member
Licensed User
Longtime User
Partendo da un esempio che ho trovato in questo sito app fa partire il video la barra è eliminata ma vorrei che il video andasse in loop se metto la in pausa si ferma se trono app riprende, questo video sarà usato come sfondo a un tabellone tipo gioco da tavolo dove ci sono celle e le pedine si muovono, ora finchè è uno sfondo ok ma mi sembrava carino mettere un piccolo video in loop come posso fare per
1) Metterlo in loop
2) Fermarlo in pausa e riprenderlo quando sono in app .. grazie mille
 

Sagenut

Expert
Licensed User
Longtime User
Ti allego una versione modificata.
Non avendo mai usato prima ExoPlayer potrei aver fatto cose errate.
Prova e fai sapere.
Purtroppo, ci ho pensato dopo, ho eliminato tutto il tuo codice che pensavo non servisse per avere meno confusione nel codice.
Quindi mi spiace ma ti toccherà fare un pò di fatica se vorrai fare un confronto con il tuo codice.
Mea Culpa.
Nel progetto che ti allego ho eliminato il file video per poterlo postare.
Quindi dovrai riaggiungerlo per poter eseguire l'esempio modificato.
 

Attachments

  • ExoPlayerExample_MOD.zip
    14.8 KB · Views: 31

sirjo66

Well-Known Member
Licensed User
Longtime User
..... e trasformare il video in una GIF animata ??
 

ken87

Active Member
Licensed User
Longtime User
Grazie funziona :)
Preferisco il video visto che lo posso creare , non sono come ringraziarti
 

Sagenut

Expert
Licensed User
Longtime User
Come hai visto è stato più facile partendo dal tuo progetto.
Mi sembra che ti stavi infilando per vie decisamente complicate mentre bastava molto meno.
Felice di averti dato una mano.
 
Top