• Introducing XDA Computing: Discussion zones for Hardware, Software, and more!    Check it out!

[MOD] YouTube that always defaults to high quality

Search This thread

jonasl

Senior Member
Nov 13, 2009
380
171
San Francisco, CA
I got fed up with the YouTube app starting videos in normal quality. To watch high quality I had to click menu and select it. The app is supposed to default to a quality suitable for your current connection but IMHO it sucks at that.

My solution was to mod the app so it always defaults to high quality. It was a 2 minute hack using apktool from brut.all (great tool, thanks!). Changes was made to PlayerActivity.smali. All I did was to remove a if condition statement by adding a # first on the line (comment) so preferHiRes always is true.

Code:
    .line 166
    invoke-virtual {p0}, Lcom/google/android/youtube/PlayerActivity;->getNetworkSpeed()I

    move-result v0

    const/4 v1, 0x3

    #if-ne v0, v1, :cond_0

    const/4 v0, 0x1

    :goto_0
    iput-boolean v0, p0, Lcom/google/android/youtube/PlayerActivity;->preferHiRes:Z

    .line 168
    invoke-direct {p0}, Lcom/google/android/youtube/PlayerActivity;->loadYouTubePlayer()V

Source apk is YouTube.apk from gapps-passion-EPE54B-signed.zip.
Download HQ mod

Install (root required, tested on CM 5.0.6):
Extract the apk from the zip (it's NOT a flashable update.zip)
Push it to /system/app
Code:
adb remount
adb push YouTube.apk /system/app/YouTube.apk

This mod is provided as is without guarantees. It works for me and I though I'd share it in case anyone else wanted it. Nandroid first is always good.
 
Last edited:

jonasl

Senior Member
Nov 13, 2009
380
171
San Francisco, CA
Missed the other one completely... I didn't look for app mods in the Q&A section :p

To get normal quality as default you should ensure that the boolean variable preferHiRes always is false. There are several ways to do this. A rough translation of the original assembly code to java would look something like this


Code:
if(getNetworkSpeed() == 3)
   preferHiRes = true;
else
   preferHiRes = false;
loadYouTubePlayer()

My mod takes away the if so the code logically runs like this
Code:
if(true)
   preferHiRes = true;
else
   preferHiRes = false;
loadYouTubePlayer()

You want something like

Code:
if(true)
   preferHiRes = false;
else
   preferHiRes = false;
loadYouTubePlayer()

This could be done like this

Code:
    .line 166
    invoke-virtual {p0}, Lcom/google/android/youtube/PlayerActivity;->getNetworkSpeed()I

    move-result v0

    const/4 v1, 0x3

    #if-ne v0, v1, :cond_0

    const/4 v0, 0x0

    :goto_0
    iput-boolean v0, p0, Lcom/google/android/youtube/PlayerActivity;->preferHiRes:Z

    .line 168
    invoke-direct {p0}, Lcom/google/android/youtube/PlayerActivity;->loadYouTubePlayer()V

Notice that I have only changed const/4 v0, 0x1 to const/4 v0, 0x0. This corresponds to the pseudo java code outlined above.

Of course one could rewrite it all a little bit more for easier reading:
Code:
preferHiRes = false;
loadYouTubePlayer()

This would correspond to
Code:
    .line 166

    const/4 v0, 0x0

    iput-boolean v0, p0, Lcom/google/android/youtube/PlayerActivity;->preferHiRes:Z

    .line 168
    invoke-direct {p0}, Lcom/google/android/youtube/PlayerActivity;->loadYouTubePlayer()V

    .line 169
    return-void

.end method

Find .line 166 in PlayerActivity.smali and substitute everything between it and .end method with the snippet above. Change const/4 v0, 0x0 to const/4 v0, 0x1 to default to high quality.

Hope you learned something from this... I know I suck at explaining things that I think are simple but I'm trying :) Sharing knowledge is what pushes this and other communities forward.
 

osanvc

Member
May 7, 2010
37
1
wow~thanks!!!!
it works for my hero!

btw, do you know how can i set my location in this app?
my previous youtube app's front page showed the video according to my location(Hong Kong :p) such as Most viewed, most discussed...etc...

but now seems to be connected to worldwide...
 

jonasl

Senior Member
Nov 13, 2009
380
171
San Francisco, CA
No idea about the localization. Everything changed is outlined above (ie I haven't touched it). I would guess that the application checks your locale to determine what to show since that's how other Google stuff works (GeneWidget for example). Maybe other versions of the apps works different from this one.
 

osanvc

Member
May 7, 2010
37
1
thanks for your reply!
actually i've tried several versions of Youtube.apk...
only some older versions could check my locale correctly, but, those are not high quality supported in 3G connection...

it's there any methods that can change the older versions youtube.apk to default always high quality??
 

osanvc

Member
May 7, 2010
37
1
Wow~finally I did it too!

I followed your instruction and usee apktool to modify the older version YouTube.apk and it really work on my Hero

There was some differents as it didn't have PlayerActivity.smali, instead, i found YouTubeplayer.smali which is similar to it.
I just removed the whole line of ' if-ne v0, v1, :cond_0 ' and didn't change anything.

Really thanks for your instruction. I can now see the local high quality videos!

File is uploaded in case someone needs.
 

Attachments

  • YouTube.apk
    296 KB · Views: 17

crimsondr

Senior Member
May 6, 2010
275
18
I tried to push the YouTube.apk to /system/app/YouTube.apk but it gives me an error about read only file system.

Does anyone know how to solve this?

Thanks.
 

jonasl

Senior Member
Nov 13, 2009
380
171
San Francisco, CA
not to be condescending, but a youtube that defaults to HQ was done like back in january...

http://alldroid.org/threads/14738-app-script-xUltimate-v1.2.4-**UPDATED-02-17-10**

and thats just to show that a patcher xeudoxus created already had it implemented by the end of january...i dont remember exactly how much further back it was actually released.

Off topic: Not getting what you are trying to say and the link doesn't contain any details. Personally I don't really care if someone made a similar or identical mod before me. I'm not in for the attention. I'm in for the fun of it and then share stuff I think others will enjoy as well (including the know how). Also, this mod isn't exactly that advanced so anyone with some basic Dalvik experience could have done it independently just as I did.


On topic:

If you are getting messages about xml parser errors (that can just be dismissed my hitting back):

I've been getting this more and more myself both prior to applying my HQ mod and afterward. It's not related, not if you are using my mod anyway. What's changed in my mod is described in detail in this thread and it's not related to xml parsing. Several users of stock firmware have this issue as well, here are some examples:

http://www.google.com/support/forum/p/android/thread?tid=7520c38a6e2e4ce3&hl=en

http://www.google.com/support/forum/p/android/thread?tid=44b225740841f9d4&hl=en

http://www.droidforums.net/forum/te...ggestions/20880-connection-error-youtube.html

The solution seems to be to clear the YouTube data and cache in Manage Applications. Try this if you run into this issue.
 

gj13

Member
Feb 28, 2010
44
5
37
Always HQ built into version 1.6.20

I just discovered that Youtube version 1.6.20 has this option built in already. It's in the settings menu. I pulled it from Paul's Desire rom and it works perfectly. It also has a HQ toggle button on the right side of the time slider.