For the last few weeks, I've ditched my iPhone in favor of a HTC Dream. I've been using
manup's Eclair rom since I got my Dream.
There's a lot to love about Android. The platform is open source, the SDKs are readily available, and best of all, it's based on the Linux kernel. My impressions of it have all been good thus far. Although, with manup's rom, viewing high quality YouTube videos doesn't seem to work.
After getting irritated, I managed to create a
workaround (apk). Below are the details of how I did it, and how to install it, for the curious.
I was doing a bit of research on reverse-engineering Android apps, and came across
smali - a disassembler/reassembler for dalvik (Android's Java-like VM) object code. I'd been getting red-assed for a while over the YouTube issue, so I decided that I would give smali a try.
Disassembling the app went like this:
$ mkdir -p youtube ; cd youtube ; unzip ../YouTube.apk
$ mkdir -p dump ; java -jar ~/Downloads/baksmali-1.1.jar -o dump classes.dex
Now, I could peer into the disassembled code in the
dump folder.
To fix the app, the solution that came to mind was to force all videos to render in normal (low) quality. After digging around for some time, I finally found the part I needed to change:
com.google.android.youtube.model.VideoInfo.
The function to fetch the high quality stream URL is named
getStreamUrlHiRes():
.method public getStreamUrlHiRes()Ljava/lang/String;
.registers 2
.prologue
.line 262
iget-object v0, p0, Lcom/google/android/youtube/model/VideoInfo;->streamUrlHiRes:Ljava/lang/String;
return-object v0
.end method
In Java, this would look like (assuming
this represents an instance of
com.google.android.youtube.model.VideoInfo):
public String getStreamUrlHiRes
() { return this.
streamUrlHiRes;
}
If you poke around enough in the class, you'll notice that the low/normal quality URL is called
streamUrlLoRes, so the fix is fairly simple:
s/streamUrlHiRes/streamUrlLoRes/. You can download a patch
here.
Now, to reassemble the individual classes:
$ java -jar ~/Downloads/smali-1.1.jar -o ../classes.dex com
Repackage the apk:
$ cd .. ; rm -rf dump ; zip -9 YouTube.apk *
Install it:
$ adb shell
# cd /data/dalvik-cache
# rm *YouTube.apk@classes.dex
$ adb push YouTube.apk /data/app_s/YouTube.apk
Now, sit back and watch some YouTube.