Android Question Youtube Player not Working

achank

Member
Hi everyone, I hope you're all staying healthy. Sorry, I'm having a problem, but perhaps some of you have also experienced this and are willing to share a solution. I've been using this library for two years https://www.b4x.com/android/forum/threads/androidyoutubeplayer.70948/ and about a week ago, it stopped working. I assume it's due to a new policy or rule from YouTube, causing the YouTube player to stop playing videos.
This is the simple code I used
YoutubePlayerView:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
    #AdditionalRes: D:\B4A\Exoplayer\Youtube view player 2\res
    #AdditionalJar: com.android.support:support-v4
'    #Extends: android.support.v7.app.AppCompatActivity
    #BridgeLogger: True
#End Region
    
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub
Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim yt As YouTubePlayerView
    Private Panel1 As Panel
    Private ButtonPause As Button
    Private ButtonPlay As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("layout")
    yt.Initialize("yt")   
    Panel1.AddView(yt,0,0,100%x,50%y)
End Sub

Sub yt_ready
    Log("Youtube view is ready")
    yt.loadVideo("IRzni8851wI", 0) '4YwNW8OlvqU
    yt.playVideo
End Sub
Sub Activity_Resume
    Log("Resume")
    yt.loadVideo("IRzni8851wI", 0) '4YwNW8OlvqU
    yt.playVideo
End Sub
Sub yt_enterfullscreen
    Log("FullScreen")
'    yt.loadVideo("UnmznFua_9s", 0)
'    yt.playVideo
End Sub
Sub yt_exitfullscreen
    Log("ExitFullScreen")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    yt.release
    Log("Pause")
End Sub

Private Sub ButtonPause_Click
    yt.pauseVideo
End Sub

Private Sub ButtonPlay_Click
    yt.loadVideo("IRzni8851wI", 0) '4YwNW8OlvqU
    yt.playVideo
End Sub

The libraries I used are appcompat and youtubeplayerview , Thank you for your attention.
 

MarcoRome

Expert
Licensed User
Longtime User
See:

 
Upvote 0

achank

Member
hi @MarcoRome Thanks for suggestion, but it same, not work for me
See:

Play YouTube Video on WebView or SMM (SOLVED)

Hello everyone, i've been searching for a couple of days and have not found a reliable way to play a youtube video the way I need to. I have a video that I will be showing in my app, it's a tutorial video, I need the video to automatically start playing as soon as it loads and it needs to play...
www.b4x.com
www.b4x.com

B4X:
*** mainpage: B4XPage_Created
*** mainpage: B4XPage_Appear
*** mainpage: B4XPage_Resize [mainpage]
resizing page
MethodName: handle
args(0): WebEvent [source = javafx.scene.web.WebEngine@4e887fb8, eventType = WEB_ALERT, data = Player_Ready:true]
message: Player_Ready:true
MethodName: handle
args(0): WebEvent [source = javafx.scene.web.WebEngine@4e887fb8, eventType = WEB_ALERT, data = Player_Error:153]
message: Player_Error:153
called from js: true
javacript is enabled: true
error: 153
page finished:
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private CustomListView1 As CustomListView
    Private MediaManager As SimpleMediaManager
    Private pnlWebView As B4XView
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")
   
    MediaManager.Initialize
    Dim s As String = "https://youtu.be/4M7RyV1zqRU"
    For i = 0 To 10
        Dim base As B4XView = xui.CreatePanel("")
        base.SetLayoutAnimated(0, 0, 0, Root.Width, 300dip)
        base.Color = xui.Color_White
        CustomListView1.Add(base, s)
    Next
End Sub

Private Sub CustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For i = 0 To CustomListView1.Size - 1
        Dim IsVisible As Boolean = i >= FirstIndex - 2 And i <= LastIndex + 2
        Dim base As B4XView = CustomListView1.GetPanel(i)
        If IsVisible Then
            If base.NumberOfViews = 0 Then
                base.LoadLayout("Item")
                Dim site As String = CustomListView1.GetValue(i)
                base.GetView(1).Text = site          
                MediaManager.SetMediaWithExtra(pnlWebView, site, "", CreateMap(MediaManager.REQUEST_CALLBACK: Me))  
            End If
        Else
            If base.NumberOfViews > 0 Then
                MediaManager.ClearMedia(base.GetView(2)) 'immediately stop WebView.
            End If
            base.RemoveAllViews
        End If
    Next
End Sub



Sub SMM_MediaReady (Success As Boolean, Media As SMMedia)
    Log("Vedo")
    Log($"${Media.Meta} ${Media}"$)
End Sub

1761893069928.png
 
Upvote 0

achank

Member
hi @MarcoRome, Thank you for your time, I've tried your code and it works.
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private CustomListView1 As CustomListView
    Private MediaManager As SimpleMediaManager
    Private pnlWebView As B4XView
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")
  
    MediaManager.Initialize
    Dim s As String = "https://youtu.be/4e9JaH9T34E"
    Dim base As B4XView = xui.CreatePanel("")
    base.SetLayoutAnimated(0, 0, 0, Root.Width, 100%y)
    base.Color = xui.Color_White
    CustomListView1.Add(base, s)
    base.LoadLayout("item")
    Dim site As String = CustomListView1.GetValue(0)
    MediaManager.SetMediaWithExtra(pnlWebView, site, "", CreateMap(MediaManager.REQUEST_CALLBACK: Me))
End Sub
yt.jpg

But what I actually need is a display like the YouTube player that I'll use on my Android TV box, and it requires a fullscreen display and autoplay, including sound, including sound, like the one I've used before https://www.b4x.com/android/forum/threads/play-youtube-video-in-android-tv-app.159024/post-987564
ma
yt player.jpg
ybe you can make a simple code, i really appreciate it
 
Upvote 0
Top