Reputation: 752
I'm starting an activity from a broadcastreceiver that turns the screen on and dismisses the lockscreen(by using windowmanager flags). This part is working as planned, the activity starts. In onCreate I initialize a YouTubePlayerView and start playing a certain YouTube video. This works as planned on my Galaxy S2, but on my Nexus 7 and my Galaxy Note 2 the YouTube video doesn't start and gives me a message in the YouTubePlayerView showing "invalid request".
Now, I thought about this and know this API can cause some weird behaviour. I came up with the option that the screen wasn't fully on and this caused the video to not load, I used this to check if the screen was on before calling initialize on the YouTubePlayerView:
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
ScreenOn = pm.isScreenOn();
if(ScreenOn){
playerView.initialize(DEVELOPER_KEY, this);
}else{
Toast.makeText(this, "SCREEN ON LATE", Toast.LENGTH_LONG).show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
myHandler.post(updateRunnable);
}
}, 2000);
}
So if the screen isn't on, I wait 2 seconds and try again to initialize the YouTubePlayerView. I spare you the code in of the myHandler cause it just works by calling initialize afterwards.
For some reason it still giving me the "invalid request" message. I can see the initialize take place but then everything stops and the same message pops up. LogCat shows nothing, no errors or weird behavior. I tried this on my S2, it just starts the video without any problems. But on the Note 7 and Note 2 the problem persist.
I used the YouTube API before, I never had this kind of problem.
edit: onError gives me back nothing more than INTERNAL_ERROR, so that isn't of any help.
Upvotes: 2
Views: 1260
Reputation: 752
I figured it out. This is really weird, I use the link provided by the Android YouTube app(by using the share button). Then I extract the video ID by using String.substring. What happens, I started building this based on my S2, if I get the YouTube link by getting the extra's in the intent the returned string looks like this:
https://www.youtube.com/watch?v=VIDEOID
&feature=youtube_gdata_player
If I try this on my N7 or Note 2 it returns:
http://www.youtube.com/watch?v=VIDEOID
&feature=youtube_gdata_player
So a https link vs a http link. On my S2 I'm running CM, so maybe that's the cause of the player returning me a secure link, but of course there are now 2 scenario's for substring.
Upvotes: 1