Youtube doesn't work

Johnmcenroy

Active Member
Licensed User
Longtime User
I have a CustomListView with panels conataining checkbox , label and images.
On click on image youtube loads video. It works only the first time then when i press back button to return to my app and click again on image immediately it doesn't work - only after nearly 5-10 seconds. I looked at logs seems that app Resumes twice and only after second resumes Youtube works again.

Here is my code for click on image:

B4X:
Sub imgScroll_Click
   Dim index As Int
   index = clvScroll.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clvScroll.GetPanel(index)
   
   Dim lbl As Label
   lbl = pnl.GetView(1)
   Dim img As ImageView
   img = pnl.GetView(2)
   
   For i=0 To WidgetService.YouTubeMap.Size-1
     If clvScroll.GetValue (index)=WidgetService.YouTubeMap.GetKeyAt(i) Then
         Msgbox (clvScroll.GetValue (index),WidgetService.YouTubeMap.GetValueAt(i))
          YouTube.Initialize(YouTube.ACTION_VIEW,WidgetService.YouTubeMap.GetValueAt(i))
        YouTube.SetComponent("com.google.android.youtube/.WatchActivity")
          YouTube.PutExtra("",WidgetService.YouTubeMap.GetValueAt(i))
          StartActivity (YouTube)
        Exit
     End If
   Next
End Sub

MsgBox show correct values , beside it doesn't work just with simple string without loop. What is wrong ?

Log.PNG


Thanks
 
Last edited:

Johnmcenroy

Active Member
Licensed User
Longtime User
Add a delay before starting the YouTube activity. Do it yourself or in code and see if it makes any change.

If you have tried this, did you get the same response?
What happens on the forth attempt and the fifth?
Does the pattern repeat every other time?

Doesn't work also with delay. I changed Youtube to Browser Intent:

B4X:
Sub imgScroll_Click
   Dim index As Int
   index = clvScroll.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clvScroll.GetPanel(index)
   
   Dim lbl As Label
   lbl = pnl.GetView(1)
   Dim img As ImageView
   img = pnl.GetView(2)
   
   For i=0 To WidgetService.YouTubeMap.Size-1
     If clvScroll.GetValue (index)=WidgetService.YouTubeMap.GetKeyAt(i) Then
         Msgbox (clvScroll.GetValue (index),WidgetService.YouTubeMap.GetValueAt(i))
          'YouTube.Initialize(YouTube.ACTION_VIEW,WidgetService.YouTubeMap.GetValueAt(i))
        'YouTube.SetComponent("com.google.android.youtube/.WatchActivity")
          'YouTube.PutExtra("",WidgetService.YouTubeMap.GetValueAt(i))
          'StartActivity (YouTube)
         Dim Internet As Intent
          Internet.Initialize(Internet.ACTION_VIEW,"http://www.google.com/")
          StartActivity (Internet)
        Exit
     End If
   Next
End Sub

All works fine. Seems like youtube with such parameters in loop doesn't work well. Don't now what it can be.
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
What about the 4 and 5 start? Would they start? You said 1 was good, 2 would not work and 3 was fine. Does that pattern continue if you try to run 4,5 and 6, etc?

With Youtube Intent works every 4-5 run depending how ofthen you click. So if i set delay nearly 10 seconds it also works. Browser Intent works as it should work.
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
That's why I ask the question. I think it was not gettting the PutExtra data because it was shutting down, etc. It just cannot take two intents that close together.

But this code also works the same :

B4X:
Sub imgScroll_Click
   Dim index As Int
   index = clvScroll.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clvScroll.GetPanel(index)
   
   Dim lbl As Label
   lbl = pnl.GetView(1)
   Dim img As ImageView
   img = pnl.GetView(2)
   
   'For i=0 To WidgetService.YouTubeMap.Size-1
     'If clvScroll.GetValue (index)=WidgetService.YouTubeMap.GetKeyAt(i) Then
         'Msgbox (clvScroll.GetValue (index),WidgetService.YouTubeMap.GetValueAt(i))
          'YouTube.Initialize(YouTube.ACTION_VIEW,WidgetService.YouTubeMap.GetValueAt(i))
        'YouTube.SetComponent("com.google.android.youtube/.WatchActivity")
          'YouTube.PutExtra("",WidgetService.YouTubeMap.GetValueAt(i))
          'StartActivity (YouTube)
        'Dim Internet As Intent
         'Internet.Initialize(Internet.ACTION_VIEW,"http://www.google.com/")
         'StartActivity (Internet)
        'Exit
     'End If
   'Next
   
   YouTube.Initialize(YouTube.ACTION_VIEW,"http://www.youtube.com/watch?v=VMBTVBENb-g")
    StartActivity (YouTube)
End Sub

When I click on butoon to run Youtube
YouTube Doesn't Work: logs show that Activity Main Paused but then immediately Resumes
YouTube Works: logs show that Activity Main Paused

With Browser Intent all works
Don't understand why app resumes itself after pause with YouTube Intent
 
Last edited:
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
The youtube app handles the request different. The browser starts loading and you click and redirect and it changes and starts loading again. YouTube completes the object before another selection can be made. If you decide to use youtube, you may have to use the delay. Let's hope someone else may have a better solution but I think that is how it will work. This may be because the youtube app has one instance and the browser can have many.
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
The youtube app handles the request different. The browser starts loading and you click and redirect and it changes and starts loading again. YouTube completes the object before another selection can be made. If you decide to use youtube, you may have to use the delay. Let's hope someone else may have a better solution but I think that is how it will work. This may be because the youtube app has one instance and the browser can have many.

Thank you for help .
But I cannot understand why in my app it doesn't work and for example in this simple works:

B4X:
'Activity module
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 YouTube As Intent
   Dim btnVideo As Button
   Dim Button1 As Button
   Dim Button2 As Button
   Dim Button3 As Button
   Dim Button4 As Button
   Dim Button5 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("1")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub btnVideo_Click
   YouTube.Initialize(YouTube.ACTION_VIEW,"http://www.youtube.com/watch?v=VMBTVBENb-g")
   YouTube.SetComponent("com.google.android.youtube/.WatchActivity")
    YouTube.PutExtra("","http://www.youtube.com/watch?v=VMBTVBENb-g")
    StartActivity (YouTube)
End Sub

I press back button and all works again and again.
 
Upvote 0

Johnmcenroy

Active Member
Licensed User
Longtime User
Put the sample sub in your project and add a Button to call it. It should work just like the sample. If it does then there is other code in between in your first sub you posted that is causing the issue.

Do you have any Activity pause and resume code in your project?

No I have not. Seems like an issue of phone , i have tested on another - works fine. On first phone there is a problem with memory and maybe system shutdown youtube. On both Android 4.0 official ROM.

Thanks for help.
 
Upvote 0
Top