Android Question Stop Player1 (simpleExoPlayerView1) using a button

Colin Evans

Active Member
Licensed User
Hi, I am using a small menu screen to launch four video's (MP4 files) this is working fine and loads another layout, the video plays and to return to the main menu I have a simple button but the video continues to play in the background and if I choose another from the main menu the video is correct but I have the audio from the background and the newly selected video

How can I stop the video playing with the back button1_click

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("albie2")
    If FirstTime Then
        player1.Initialize("player")
        player1.Prepare(player1.CreateFileSource(File.DirAssets, "albie2.mp4"))
    End If
    SimpleExoPlayerView1.Player = player1
    player1.play
End Sub

Sub button1_click
    RemoveViews
    StartActivity("main")
End Sub

Sub RemoveViews
    Dim i As Int
    For i=Activity.NumberOfViews-1 To 0 Step -1
        Activity.RemoveViewAt(i)
    Next
End Sub
Hope someone can help
 

npsonic

Active Member
Licensed User
I don't understand why you wouldn't just use Pause?

B4X:
Sub button1_click
    player1.Pause
    RemoveViews
    StartActivity("main")
End Sub
 

Colin Evans

Active Member
Licensed User
I tried the player1.pause exactly as you put in button1_click and it didn't work, and what Erel says but they still keep playing

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("albie1")
    If FirstTime Then
        player1.Initialize("player")
        player1.Prepare(player1.CreateFileSource(File.DirAssets, "albie1.mp4"))
    End If
    SimpleExoPlayerView1.Player = player1
    player1.play
End Sub

Sub button1_click
    'RemoveViews
    player1.Pause
    player1.Release
    StartActivity("main")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    player1.Pause
    player1.Release
End Sub
 

Colin Evans

Active Member
Licensed User
I can't as the file is too big, I've removed three of the video's but its still 380Mb in size but even with just one video when I return back to the menu it still plays in the background
 

Colin Evans

Active Member
Licensed User
Hi I have five modules in the app, Main and then four the same which play the MP4 files, PlayerAlbie1, PlayerAlbie2 etc

the code for Main and PlayerAlbie1 is as follows the other thre are the same with the exception of the MP4 file is different

Hope you can see where I'm going wrong, I've uploaded the Main.bal and albie1.bal if you needed them

Main
B4X:
#Region  Project Attributes 
    #ApplicationLabel: Albie's 
    #VersionCode: 1
    #VersionName: 
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: true
#End Region

#Region  Activity Attributes 
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private ImageView1 As ImageView
    Private ImageView2 As ImageView
    Private ImageView3 As ImageView
    Private ImageView4 As ImageView
    End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
   
End Sub

Sub imageview1_click
    StartActivity(PlayerAlbie1)
End Sub

Sub imageview2_click
    StartActivity(PlayerAlbie2)
End Sub
Sub imageview3_click
    StartActivity(PlayerAlbie3)
End Sub
Sub imageview4_click
    StartActivity(PlayerAlbie4)
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
PlayerAlbie1
B4X:
#Region  Activity Attributes 
    #FullScreen: True
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Private player1 As SimpleExoPlayer
End Sub

Sub Globals
    Private SimpleExoPlayerView1 As SimpleExoPlayerView
    Private button1 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("albie1")
    If FirstTime Then
        player1.Initialize("player")
        player1.Prepare(player1.CreateFileSource(File.DirAssets, "albie1.mp4"))
    End If
    SimpleExoPlayerView1.Player = player1
    player1.play
End Sub

Sub button1_click
    player1.Pause
    player1.Release
    StartActivity("main")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    player1.Pause
    player1.Release
End Sub

Sub Activity_Resume
    Activity.LoadLayout("albie1")
    player1.Initialize("player")
    player1.Prepare(player1.CreateFileSource(File.DirAssets, "albie1.mp4"))
    SimpleExoPlayerView1.Player = player1
    player1.play
End Sub
 

Attachments

Top