B4A Library AndroidYouTubePlayer

Enjoy this library from B4A https://github.com/PierfrancescoSoffritti/AndroidYouTubePlayer

YouTube player based on WebView, because the one provided by Google is soo bad :| (Original library words :D )


ayp.gif


Notes:
B4X:
@DependsOn(values={"android-support-v4"})
Uses appcompat library
YouTubePlayerView
Author:
SMM
Version: 0.01
  • YouTubePlayerView
    Events:
    • _enterfullscreen
    • _exitfullscreen
    • _ready
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • cueVideo (videoId As String, startSeconds As Float)
    • enterFullScreen
    • exitFullScreen
    • isFullScreen As Boolean
    • loadVideo (videoId As String, startSecond As Float)
    • pauseVideo
    • playVideo
    • release
    • seekTo (time As Int)
    • showTitle (show As Boolean)
    • toggleFullScreen
    Permissions:
    • android.permission.ACCESS_NETWORK_STATE
    • android.permission.INTERNET
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int



Sample :

B4X:
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
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("Layout1")
    yt.Initialize("yt")

    Activity.AddView(yt,0,0,100%x,50%y)
      
End Sub

Sub yt_ready
    Log("Youtube view is ready")
    yt.loadVideo("UwikLSIm1UI", 0)
    yt.playVideo
End Sub
Sub Activity_Resume

End Sub
Sub yt_enterfullscreen
    Log("FullScreen")
  
End Sub
Sub yt_exitfullscreen
    Log("ExitFullScreen")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
    yt.release
End Sub
 

Attachments

  • YouTubePlayerView.zip
    38.5 KB · Views: 177
  • youtuberes.zip
    6.8 KB · Views: 184
Last edited:

analizer3816

Member
Licensed User
thanks for great library.
I copy all files in youtuberes.zip to objects/res and set them to read only
but I have error at yt.Initialize("yt")

can you or anyone suggest me about this error?

thanks in advanced

B4X:
Error occurred on line: 33 (Main)
android.view.InflateException: Binary XML file line #46: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at android.view.View.inflate(View.java:18457)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:50)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:39)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:35)
    at smm.youtubevwrapperp.youtubevwrapper._initialize(youtubevwrapper.java:73)
    at smm.youtubevwrapperp.youtubevwrapper.Initialize(youtubevwrapper.java:63)
    at b4a.example.main._activity_create(main.java:377)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:600)
    ... 35 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_play_36dp.xml from drawable resource ID #0x7f020059
    at android.content.res.Resources.loadDrawable(Resources.java:3066)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
    at android.widget.ImageView.<init>(ImageView.java:133)
    at android.widget.ImageView.<init>(ImageView.java:123)
    ... 38 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
    at android.content.res.Resources.loadDrawable(Resources.java:3062)
    ... 41 more
 

MarcoRome

Expert
Licensed User
thanks for great library.
I copy all files in youtuberes.zip to objects/res and set them to read only
but I have error at yt.Initialize("yt")

can you or anyone suggest me about this error?

thanks in advanced

B4X:
Error occurred on line: 33 (Main)
android.view.InflateException: Binary XML file line #46: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:626)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
    at android.view.View.inflate(View.java:18457)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:50)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:39)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:35)
    at smm.youtubevwrapperp.youtubevwrapper._initialize(youtubevwrapper.java:73)
    at smm.youtubevwrapperp.youtubevwrapper.Initialize(youtubevwrapper.java:63)
    at b4a.example.main._activity_create(main.java:377)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:600)
    ... 35 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_play_36dp.xml from drawable resource ID #0x7f020059
    at android.content.res.Resources.loadDrawable(Resources.java:3066)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
    at android.widget.ImageView.<init>(ImageView.java:133)
    at android.widget.ImageView.<init>(ImageView.java:123)
    ... 38 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:986)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:930)
    at android.content.res.Resources.loadDrawable(Resources.java:3062)
    ... 41 more


Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_play_36dp.xml from drawable resource ID #0x7f020059
This mean that you havent copied Resource Folder in your project.
If you see in #1 you have youtuberes.zip , copy this file, uncompress in folder and add in your project with #Addtionalres: ..\namefolderuncompress, anyway you can see also another my answer HERE
 

analizer3816

Member
Licensed User
This mean that you havent copied Resource Folder in your project.
If you see in #1 you have youtuberes.zip , copy this file, uncompress in folder and add in your project with #Addtionalres: ..\namefolderuncompress, anyway you can see also another my answer HERE
yes,I do it both copy to objects/res and
#AdditionalRes: ..\res and use appcompat library
>> it works well on android 6.0.1 but show above error on android 4.4

I loaded sample apk from https://github.com/PierfrancescoSoffritti/AndroidYouTubePlayer
and run on android 4.4, it works
 
Last edited:

somed3v3loper

Well-Known Member
Licensed User
yes,I do it both copy to objects/res and
#AdditionalRes: ..\res and use appcompat library
>> it works well on android 6.0.1 but show above error on android 4.4

I loaded sample apk from https://github.com/PierfrancescoSoffritti/AndroidYouTubePlayer
and run on android 4.4, it works
I do not know but try not to copy to Objects/res and delete files you already copied to that folder .
Instead , just extract res files attached to first post and let #AdditionalRes: point to its folder
 

hanyelmehy

Active Member
Licensed User
i have same problem above when test on android 4.0 and 4.4
B4X:
android.view.InflateException: Binary XML file line #46: Error inflating class <unknown>
    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
    at android.view.View.inflate(View.java:17832)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:50)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:39)
    at com.pierfrancescosoffritti.youtubeplayer.YouTubePlayerView.<init>(YouTubePlayerView.java:35)
    at smm.youtubevwrapperp.youtubevwrapper._initialize(youtubevwrapper.java:73)
    at smm.youtubevwrapperp.youtubevwrapper.Initialize(youtubevwrapper.java:63)
    at b4a.example.main._activity_create(main.java:391)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:708)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at b4a.example.main.afterFirstLayout(main.java:102)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:80)
    at android.os.Handler.handleCallback(Handler.java:808)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5299)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Constructor.constructNative(Native Method)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
    ... 35 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_play_36dp.xml from drawable resource ID #0x7f020059
    at android.content.res.Resources.loadDrawable(Resources.java:2152)
    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
    at android.widget.ImageView.<init>(ImageView.java:129)
    at android.widget.ImageView.<init>(ImageView.java:119)
    ... 38 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag vector
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
    at android.content.res.Resources.loadDrawable(Resources.java:2148)
 
Top