Audio For Everybody!

When The Love Falls by Sean OoiDownload Audio: Audio Format "MP3" | Audio Format "OGG"

Prologue

A few posts back I used the new HTML 5 video tag to display a video. That chunk of code was written by Kroc Camen and is compatible across most major browsers, including IE and the iPhone. One of the reasons I like it is because there is no JavaScript involved, making it lightweight.

It was his Video for Everybody post that inspired me to write this post. I figured since there's a cross-browser compatible code for the video tag, it would only be right to have one for the audio tag as well; A simple Google search came up with one related site that was very poorly written, so I decided to write one myself, based heavily on Kroc's code.

I've tested my codes on the iPhone and on common web browsers which includes Firefox, Safari and Opera on both Windows and Mac OS X, and Google Chrome and IE on Windows.

Compatibility

The code is validated as HTML 5. It will first try the HTML 5 playback, and fallback to flash if needed. If neither works, it will display an image showing users that no streaming capability is available and will ask to download the file instead.

  • Firefox 3.5: HTML5-OGG
  • Safari 4 (Mac): HTML5-MP3
  • Safari 4 (PC): HTML5-MP3→Flash
  • iPhone OS 3.1.2: HTML5-MP3 (Small play area due to the lack of the width & height attribute)
  • Opera 10: QT→Flash
  • Chrome 3: HTML5-OGG
  • <= IE 6: Flash
  • >= IE 7: Windows Media Player
Firefox

Firefox

Chrome

Chrome

IE

IE

iPhone

iPhone

Opera

Opera

The Code

<!-- Try HTML 5 playback first. -->
	<audio controls="controls">
	<source src="__AUDIO__.OGG" type="audio/ogg" /> <!-- Firefox and Chrome -->
	<source src="__AUDIO__.MP3" type="audio/mpeg" /> <!-- Safari and iPhone -->

<!-- Windows Media Player class id to enable native streaming on IE 7 and above. IE 6 and below will go straight to flash player -->
	<!--[if gt IE 6]>
	<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="320" height="45"><!
	[endif]-->

	<!--[if !IE]><!-->
	<object type="audio/mpeg" data="__AUDIO__.MP3">
	<!--<![endif]-->

<!-- Windows Media Player controls -->
	<param name="url" value="__AUDIO__.MP3" />
	<param name="autostart" value="false" />
	<param name="uiMode" value="full" />

<!-- Flash fallback -->
	<object height="24" width="320" type="application/x-shockwave-flash" data="__FLASH__.SWF" id="audioplayer">
	<param name="movie" value="__FLASH__.SWF" />
	<param name="FlashVars" value="playerID=audioplayer&amp;soundFile=__AUDIO__.MP3" />

<!-- Fallback image when nothing works -->
	<img class src="__POSTER__.JPG" width="128" height="135" alt="Title" title="No audio playback capabilities, please download the audio below" />

	</object><!--[if gt IE 6]><!-->
	</object><!--<![endif]-->
</audio> 

<!-- Download links outside the audio tag -->
<p>Download Audio: <a href="__AUDIO__.MP3">Audio Format "MP3"</a> | <a href="__AUDIO__.OGG">Audio Format "OGG"</a></p>

The line break in line 8 is due to a bug in IE. I'm not sure if it applies to the audio tag as well, but no harm being safe. A more compact version of the source code follows.

<audio controls="controls">
	<source src="__AUDIO__.OGG" type="audio/ogg" />
	<source src="__AUDIO__.MP3" type="audio/mpeg" />
	<!--[if gt IE 6]>
	<object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" width="320" height="45"><!
	[endif]--><!--[if !IE]><!-->
	<object type="audio/mpeg" data="__AUDIO__.MP3">
	<!--<![endif]-->
	<param name="url" value="__AUDIO__.MP3" />
	<param name="autostart" value="false" />
	<param name="uiMode" value="full" />
	<object height="24" width="320" type="application/x-shockwave-flash" data="__FLASH__.SWF" id="audioplayer">
	<param name="movie" value="__FLASH__.SWF" />
	<param name="FlashVars" value="playerID=audioplayer&amp;soundFile=__AUDIO__.MP3" />
	<img class src="__POSTER__.JPG" width="128" height="135" alt="Title" title="No audio playback capabilities, please download the audio below" />
	</object><!--[if gt IE 6]><!-->
	</object><!--<![endif]-->
</audio> 
<p>Download Audio: <a href="__AUDIO__.MP3">Audio Format "MP3"</a> | <a href="__AUDIO__.OGG">Audio Format "OGG"</a></p>
Usage notes:
  • Replace __AUDIO__.MP3 with the path to your MP3 encoded file
  • Replace __AUDIO__.OGG with the path to your OGG encoded file
  • Replace __FLASH__.SWF with the path to your flash player. I use the standalone version of WordPress Audio Player
  • Replace __POSTER__.JPG with your JPEG image file for fallback purposes

One reason to put the download links outside the audio tag as said by Kroc for his Video for Everybody code: Give people your audio files—you want them to hear the audio anyway and you are fooling yourself if you think that they shouldn’t be allowed to download the audio.

I am not very confident when it comes to writing codes and explaining. In fact I suck at it, so please contact me if you spot any mistakes in my post. Any kind of help to further improve the code is welcomed as well.

Google Testing New Search Page

An update from Webmonkey shows that Google is currently testing their redesigned search page. Nothing has been mentioned on Google’s Blog yet, so it is unsure if the new search page will go live.

Changes that I’ve noticed are:

  • The Google Search button background has been changed to a blue gradient instead of the grey to white gradient.
  • Top bar link colors have been changed from Medium Blue #0000cc to Royal Blue #4272db
  • Bottom link colors have been changed to Persian Blue #1111cc
  • The Google logo drop shadow and TM branding has been removed
  • Not too sure about this, but there’s a “Make Google your homepage” link now
  • The search box has been embossed up instead of down with
  • The Advance Search and Language Tools links on the side of the search box has been removed
  • Overall dimensions look slightly larger
  • A more aesthetically pleasing visible sidebar

If you’re like me who just can’t wait until it’s official, Google Blogoscoped found a JavaScript snippet that you can use to activate the new page by following the steps below:

  1. Go to Google’s homepage
  2. Log out of your Google account if you’re logged in
  3. Paste the following code in your browser’s address bar and hit enter. It means deleting “http://www.google.com/” from the address bar and pasting the following code
javascript:void(document.cookie="PREF=ID=20b6e4c2f44943bb:U=4bf292d46faad806:TM=1249677602:LM=1257919388:S=odm0Ys-53ZueXfZG;path=/; domain=.google.com");
  1. Refresh your Google homepage

The JavaScript code sets a new cookie, which is why you have to log out of your Google account before you can see the changes. Once the cookie is set, refresh your Google homepage and you should be looking at the new Google.

Google's New Homepage

Google's New Homepage

Google's New Search Page

Google's New Search Page

SSH Into iPhone Without Wireless Router

I have always wondered if it were possible to SSH into my iPhone without a wireless router and search results on Google always pointed to no… This was before I found out that it was possible to do so.

Steps that I will be explaining will only apply to jailbroken iPhones and Macs, because I do not want to waste my time tinkering with Windows’ complicated network settings, so if you’re a PC user, I’m sorry, you’re out of luck. But if you found a way to do so, please do let me know and I can post it up as reference.

Instructions will be based on Mac OS X Snow Leopard 10.6.2 Things you will need will be of course, an iPhone, and a Mac with wireless capabilities. Which covers almost all Macs.

  1. Go into System Preference
  2. Click on Network
  3. Click on AirPort
  4. Turn AirPort on if you haven’t already
  5. Click on the Network Name dropdown menu and choose Create Network…
  6. The Name field will be your wireless name, or SSID. Leave the Channel as it is, and tick Require Password if you wish to do so.
  7. You will be asked to key in your admin password to finalize your network creation

Now that you’ve created a network, it’s time to connect your iPhone and SSH into it.

  1. Connect your iPhone like you would with any WAP.
  2. After you’re connected, give it awhile to register an IP address.
  3. Tap on the blue arrow beside your connected network to reveal your IP address. This is the address you will be using to SSH into your iPhone
  4. I like to use Coda for FTP purposes. But if you don’t have an FTP app, you can try Cyberduck
  5. Fire up your FTP app and click Connect on Coda or New Connection on Cyberduck.
  6. Change the Protocol to SFTP
  7. In the Server text field, type in the IP address you found in step 3
  8. Your username is root
  9. Your password is alpine[1]
  10. Leave the Port as 22 and click Connect

You have just SSH’ed into your iPhone without a wireless router. This method is most probably noted already somewhere on the web, but I have never been able to search for it. So hopefully this post will be of help to cheap people like me who do not want to fork out $50 for a wireless router

Reference

[1] In a previous post, I wrote on the vulnerability of not changing your iPhone’s root password and steps on how to do it. It is highly recommended that you do so as to secure your iPhone.

Officially Missing You

These 2 Australian-Korean girls have angelic voices. As a matter of fact, I think their singing is better than Tamia's, and I think you would agree too after watching the video. If you like them, you can visit their YouTube channel for more videos.

Before I forget, many thanks to Kroc Camen for his Video For Everybody HTML code. I'll probably talk more about it in later posts. The video plays natively on the iPhone, in Firefox 3.5, Safari 3 & 4 and Google Chrome. On IE, it'll revert to the God awful flash plugin that everyone loves, that is if you have the plugin installed. If not you can just go ahead and download the video.

If you're having problems with playing the video on your iPhone, try refreshing the page a few times or clicking on the direct video link

Download Video: High Quality “MP4” | Low Quality “OGG”

How To Change Your iPhone Root Password

Recently there’s been a lot of news about jailbroken iPhones being hacked and held for ransom or just having their wallpapers changed.

The reason this only happens on jailbroken iPhones is because they have the SSH daemon running, which is common in most jailbroken iPhones, with the default root password left unchanged. This will enable hackers to gain access into their iPhones and have total control over them, which basically means hijacking their phone.

They can send text messages from your number, use it to call or record your calls, and actually whatever they want, even use it for their hacking activities.

So to prevent it, all you have to do is to change your default root password, which is as easy as following the steps below:

Note1: This will only work if you have not changed your default root password before.

Note2: When typing in your password, don’t worry if nothing shows up. It’s just how it should be.

  1. If you haven’t installed MobileTerminal yet, go to Cydia and search for “MobileTerminal” and install the app.
  2. Launch MobileTerminal, type in su and hit return.
  3. When asked to key in your password, type in alpine and hit return.
  4. You are now logged into your phone as the root user. Now type in passwd and hit return.
  5. You will then be asked for a new password. Type in your new password and hit return.
  6. You will be asked to re-enter your password. Re-enter your new password and hit return.

You’re done! Your root password has been changed and your iPhone is secure once again for now. Right now all you have to do is to not forget what you changed your root password to.

My Blog, Now iPhone Friendly

Just a few days ago I was talking to Keefe about the iPhone version of his blog and how I’m not worried about mine because of 2 reasons:

  1. I don’t have many readers
  2. I don’t know many people who uses the iPhone

Not long after our discussion, I started noticing more and more of my friends using the iPhone, mainly through Facebook, so the latter wasn’t so true anymore, and I decided to make my blog iPhone friendly as well.

My first attempt at searching online always ended up with results with “Just install <some name> plugin and you’re good to go”, which I hated. I don’t know why, but it has always been my personal preference to have it written right into the core of my theme rather than rely on a plugin. Frustrated, I quit my web browser and watched a movie instead.

During my second attempt, I found what I was looking for. No plugins, just altering my CSS file. All I had to do was to add following @media selector in my CSS file and target any elements within the curly brackets.

@media only screen and (max-device-width: 480px) {
}

We declare max-device-width: 480px because of the iPhone’s unique screen size. To style for average mobile devices, using the following selector should be sufficient.

@media handheld{
}

These methods are a nice way of enabling web developers and designers to style their websites to be mobile friendly. But occasionally, there’s bound to be some elements that just can’t be styled the way you want them to because of the original code itself being placed so ever obscurely. The way I countered this was by using a mobile detection script and adding an if/else statement in my PHP file. That way, I can rearrange all my codes for the mobile version of my site without having to temper with the original ones.

After hours of typing and clicking on the refresh button, I’m not-so-proud to unveil the iPhone version of my site.

Main Page

Main Page

Navigation Links

Navigation Links

Landscape View

Landscape View

Mac OS X Dock Spacers

I was reorganizing my desktop when I noticed how cluttered my dock was, so I set out on a quest to find ways on how to make it look more organized and found out that adding spacers to it can help divide my applications into different sections, thus making it look cleaner and neater.

To add spacers to your dock, just fire up Terminal (Applications > Utilities) and run the following command:

defaults write com.apple.dock persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'

Don’t worry if you don’t see any changes yet, because you still need to reload the dock. To do so, just run the following command in Terminal as well.

killall Dock

Your dock will reload and you should be seeing an empty space (spacer) on your dock now. To add more, just run the first command for as many spacers as you want and reload the dock.

You can add spacers to the right side of the dock too, or also known as the “Stacks” side of the dock. To do so, just run the following command for as many spacers as you want as well, and remember reload the dock when you’re done.

defaults write com.apple.dock persistent-others -array-add '{tile-data={}; tile-type="spacer-tile";}'

To remove these spacers, just right click on them and select “Remove from Dock” or just drag them out of the dock and it’ll *poof* away.

Dock Spacers

Dock Spacers

Optimizing Websites

This question has been on my mind for quite some time already: “What makes a website a good website?” Besides that, there are other related questions that I’ve been thinking about too lately; Questions like “Why is it loading so slow?” and “Is it possible to make it load faster?” I’m no expert in anything web related, but I would like to voice out what I think and I hope that my thoughts and suggestions will be helpful to current web designers/developers, as well as those who plan to start making their own websites.

What

For now, I would just like to focus on blogs. Factors that immediately came to mind are:

  • Pictures or cute girls
  • Pictures of hot girls
  • Pictures or wannabe cute girls
  • Pictures of wannabe hot girls
  • Pictures of food (with girls posing)
  • Pictures of uncommon places (with girls posing)
  • Pictures of uncommon objects (with girls posing)
  • Childish writings by cute girls
  • Childish writings by hot girls
  • Childish writings by wannabe cute girls
  • Childish writings by wannabe hot girls
  • Fancy website designs

On the contrary, these are the factors that usually repulse readers from one’s site:

  • Pictures or males
  • Childish writings by males
  • Boring website designs

So as you can see, 7 out of the 12 factors of success I’ve just mentioned consists of pictures with girls in them, and 11 out of 12 of them are related to girls, which is pretty safe to say that pictures and girls are the main source of attraction. I like blogs with pretty pictures of girls too! Abso-fucking-lutely no doubt about that! But althought blogs with pretty pictures are somewhat aesthetically pleasing, they can come at a cost, mainly the cost of losing your readers with crappy connections, especially impatient ones with crappy connections like myself. I can’t remember the number of times I quit my web browser just because a site is taking too long to load.

Why

But occasionally when I do wait until a blog completes loading, I normally find out the reason why it’s taking forever to load just by taking a quick glance at it. These blogs have a plethora of pictures in just a single post, and vary from 5 to 10 posts on the front page. In addition to that, some of them have other fancy features like Flash headers, oversized picture headers, Flash twitter widgets, JavaScript navigational bars, videos and Flash ads to name a few.

A quick benchmark of one of these bloated sites (I shall call it blog-X) show a shocking number of items being loaded:

  • 7 Cascading Style Sheets (CSS)
  • 212 Images
  • 16 JaveScripts
  • 2 application objects

How

Blog-X has a total of 7MB+ of data to be loaded, which is fine if you have a connection of 5Mbps or more. Which means people with shitty connections, mainly Malaysia, with connection speeds that don’t justify their advertised speed of <insert fake speed here>, will suffer, and not to mention delay times and queue times, which adds up to approximately 2-3 minutes of your life drifting away, slowly, waiting for Blog-X to finish loading.

Over the years, i’ve learnt that in web designing, the most important thing to remember is loading time. Try to reduce the number of items your site loads when someone visits it. I like to assume that everyone has a slow connection; It helps to eliminate unnecessary items being loaded, mainly flash and JavaScript objects. Other ways that i’ve learnt are:

  1. Compress Cascading Style Sheets (CSS)
  2. Compress JavaScripts
  3. Optimize images

Referring back to blog-X, 7 style sheets!? Why not just put them all into 1 file? Wouldn’t it be easier to go through 1 file instead of 7 different files to find the CSS property you’re looking for?

And c’mon, 212 images?!? Do you really have to load that many? Change the number of posts that show on your front page! If you know you’re going to write a shit load of trash and upload tons of unoptimized images, then reduced it to a post, or 2 at most. No one wants to wait forever for your site to load while it’s hogging every last drop of connection speed they have. It’s just downright depressing.

Not to forget, 16 JavaScripts, consisting of a few Twitter scripts, a few web counter scripts, and a few more random widget scripts. We don’t need to know how many people visited your site, keep the numbers to yourself. We also don’t need to know when you’re going to bed, when you woke up, what you’re eating or if you’re in the shower or not. These are the type of things that your readers can live without, if not less.

One good compression script for JavaScripts and CSS I found to be very effective and easy to use is Minify. I love how you can combine like files into a single link.

If you’re using WordPress, a possible way of reducing load times is to modify your theme’s single.php file so that it displays a single post per page, while retaining the number of posts shown in your archives per page. The way to do this is to first duplicate your single.php file and rename the duplicated one to home.php. In your index.php file, paste the following code under your get_header(); line.

< ?php $wp_query->is_single = true; ?>

So it should end up looking something like this:

< ?php get_header(); ?>
< ?php $wp_query->is_single = true; ?>

Next is to open up your home.php file and paste the following code under your get_header(); line too.

< ?php
      $i=0; // Initialize to Zero;
      if (have_posts()) :
        while (have_posts()) : the_post();
            if ($i==0) {$recentpostid = $post->ID; $i=$i+1;}
        endwhile;
      endif;
      //get only the latest post
      $posts = query_posts( 'p='.$recentpostid."'");
?>

You’re done. Right now your main page should show 1 post per page in the format of single.php.

If you’re wondering why I didn’t just change the reading settings in the admin panel, it’s because if I did, the main page will indeed show 1 post per page, but if I click into my archives, it’ll also show only 1 post per page, which is really annoying if I’m trying to go through my old posts.

When it comes to uploading pictures, I like to first optimize it with Smush.itTM and post thumbnails instead of the full size, which saves on loading time and lets readers have the choice of choosing which picture they prefer to view in full size.

CSS has become so powerful now that it is capable of replacing images. If you’re using Safari 4 or Google Chrome, you should be seeing a blue gradient in my header. It’s done using CSS, not images. Same goes for the calendar on the left of this post. As mentioned in my first post, the only image I’m using for this theme is the “leafy” divider at the end of this post.

Therefore

This article my not be entirely true, but it is based on what I’ve noticed and learnt. Besides methods mentioned above, I’m sure there are other better ones available out there. If anyone would be kind enough to share, please feel free to contact me using the contact form.