some comments to YouTubeUtility.calculateYouTubeUrl

205 views
Skip to first unread message

Bruce

unread,
Mar 19, 2012, 8:52:59 AM3/19/12
to Android YouTube Player
Hi,

thank you for this project. It helped me a lot.

I'd like leave some comments might be useful to other developers using
this library.

Even though "http://www.youtube.com/get_video_info?&video_id=" API is
deprecated it gives us the best quality video URL. I found that the
new YouTube Data API ("https://gdata.youtube.com/feeds/api/videos/")
gives us RTSP(3gp) video of which quality is very poor.

Only the problem is when the video is deleted or 'dedicated' to be
played on YouTube site only. In those cases the YouTube will respond
message like this.

status=fail&errorcode=150&reason=SME%EC%9D%98+%EC%BD%98%ED%85%90%EC
%B8%A0%EB%A5%BC+%ED%8F%AC%ED%95%A8%ED%95%9C+%EB%8F%99%EC%98%81%EC
%83%81%EC%9D%B4%EB%AF%80%EB%A1%9C+%ED%8A%B9%EC%A0%95+%EC%82%AC%EC%9D
%B4%ED%8A%B8%EC%97%90%EC%84%9C%EC%9D%98+%EC%9E%AC%EC%83%9D%EC%9D%B4+%EC
%A0%9C%ED%95%9C%EB%90%A9%EB%8B%88%EB%8B%A4.%3Cbr%2F%3E%3Cu%3E%3Ca+href
%3D%27http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DebJC7DWj9Ow%26feature
%3Dplayer_embedded%27+target%3D%27_blank%27%3EYouTube%EC%97%90%EC%84%9C
+%EB%B3%B4%EA%B8%B0%3C%2Fa%3E%3C%2Fu%3E


The Error code 150 means 'it must be played on YouTube site only' and
errcode 100 means 'it is deleted'. So the current parsing logic will
just fail at those cases, you better check the exact reason why it
failed.




Pattern pattern = Pattern.compile("errorcode=(.*)&reason=(.*)");
Matcher m = pattern.matcher(lInfoStr);
boolean found = m.find();
if (found) {
String strerrcode = m.group(1);
int errcode = Integer.parseInt(strerrcode);
Strig strerrr = URLDecoder.decode(m.group(2), "UTF-8");
}


So if the errcode is 150, maybe you want to start a YouTube app
installed, for that video.

Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("http://www.youtube.com/v/" + mVideoId));
i.setPackage("com.google.android.youtube");
startActivity(i);


And the other thing I want to mention is the 'orientation' of the
Activity what "Naushad Kasu" already suggested.

<activity
android:name="com.keyes.youtube.OpenYouTubePlayerActivity"
android:configChanges="keyboard|keyboardHidden|orientation|
screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="landscape"
/>


Finally if you want to play videos repeatedly random or sequencial,
you maybe want to check the ActivityResult simply. For example you can
set ActivityResult as OK when the play is ended normally and in that
case you can check the ActivityResult to decide play the next video or
quit repetition.

final Intent intent = getIntent();
setResult(RESULT_OK, intent);
OpenYouTubePlayerActivity.this.finish();

What I hope there is and option for adding movies list to play in this
library, skip button, repeat mode, etc.

And I really want to know how can I play the movies which I get error
response 150. Don't I need to start another YouTube intent If I get
any credential token for YouTube?


Anyway, thanks for this library and I hope my comments will be helpful
to anybody.


Regards.,


BruceWang.

Mustafa Musa Ülker

unread,
Feb 17, 2013, 5:35:40 AM2/17/13
to android-you...@googlegroups.com
Hello Bruce,

I am having some problem. Did you solve this issue?
Reply all
Reply to author
Forward
0 new messages