Jump to content

Detect If Using Android O.S. Internet Browsers?


JeZxLee
 Share

Recommended Posts

Detect If Using Android O.S. Internet Browsers?

 

Hi,

 

I have a new HTML5 website here: www.16BitSoft.com

I am trying to make the new HTML5 website run on Android O.S. Internet browsers.

How can I detect if new HTML5 website is running on an Android O.S. device's Internet browser?

I tried the following code but it only works on my smartphone and not my tablet:

if (navigator.userAgent.toLowerCase().indexOf('android') > -1 ){    SoundType = "null";    Browser = "Android";}

Purpose of detecting Android O.S. Internet browser is so I can disable the new HTML5 website's audio.

Any help would be appreciated, thank you!

 

JeZxLee

16BitSoft Inc.

Video Game Design Studio

www.16BitSoft.com

Link to comment
Share on other sites

Really? I have never seen that before. I always thought that all Android browsers had "Android" in the userAgent - what tablet do you have, and what do you get if you print out the userAgent?

 

Out of curiosity, why do you want to disable audio exclusively on Android?

Link to comment
Share on other sites

Really? I have never seen that before. I always thought that all Android browsers had "Android" in the userAgent - what tablet do you have, and what do you get if you print out the userAgent?

 

Out of curiosity, why do you want to disable audio exclusively on Android?

Hi,

 

When I print "navigator.userAgent" to the screen it does not have "Android" tag in it.

It's a cheap no name Android tablet.

I wish to disable audio because HTML5 audio does not work on Android/iOS.

 

I solved this problem because the word: "Mobile" is in the "navigator.userAgent".

I also got it working on iOS devices because they have: "iPhone", "iPad", or "iPod" in the "navigator.userAgent".

Thanks!

 

JeZxLee

Link to comment
Share on other sites

As Gio said, feature detection is the way to go.

I'd suggest to use Howler, it's my favorite sound lib and it does a lot neat stuff in the background.

Just because someone is using an android device, doesn't mean that audio doesn't work. You are just taking away a huge amount of user experience with your approach. But I believe since it's for your website and it's not common to have background music on websites, since it can be really annoying, it might be fine to lock out people from that experience.

Link to comment
Share on other sites

I'm glad you sorted it out but, generally speaking, HTML5 audio works on both operating systems and it's be better to use feature detection rather than relying on the userAgent string

Hi,

 

Thanks for the reply.

 

How would I go about testing if MP3 and/or OGG audio files are playable on an Internet browser?

If you could type a small example or provide a good URL webpage link that would be great.

 

Thanks...

 

JeZxLee

Link to comment
Share on other sites

Hi,

 

I Google'd a bit and found some examples.

Is this correct:

var audioTest = document.createElement('audio');if ( audioTest.canPlayType('audio/mpeg;') )  SoundType = "mp3";else  if ( audioTest.canPlayType('audio/ogg;') )  SoundType = "ogg";else  SoundType = "null";

Thanks!

 

JeZxLee

Link to comment
Share on other sites

@JeZxLee

 

Please take my advice: Don't recreate something that people, who have the proper knowledge, have already done.

You are just spending hous over hours, over day, over weeks, to get a solution that still won't be perfect.

 

https://github.com/goldfire/howler.js

 

Howler is one of the best webaudio libs, which does everything for you.

Pleae consider using it, or any other sound lib and use the time, that you would have spend on the audio, to work ont he rest of your website or to work on your games.

 

As your codec check might work, that still won't be enough to properly provide the user with an working audio experience.

There's nothing wrong with using libs.

 

Hope that helps you!

 

(You can also look up the howler source code and look for a proper check of supported audio formats)

Link to comment
Share on other sites

@JeZxLee

...

https://github.com/goldfire/howler.js

 

Howler is one of the best webaudio libs, which does everything for you.

Pleae consider using it, or any other sound lib and use the time, that you would have spend on the audio, to work ont he rest of your website or to work on your games.

...

Hi,

 

I tried Howler.js on both my Android smartphone and tablet and it does not work.

(went to this site on devices: http://goldfirestudios.com/blog/104/howler.js-Modern-Web-Audio-Javascript-Library)

 

Jesse

Link to comment
Share on other sites

  • 2 weeks later...

I've been looking into html5 sound this for a recent game i made, and spent way too long trying to fix the sound sacross desktop browsers and mobile browsers alike -

 

"feature detection" was also suggested to me, but i found, like hyml5 audio support is a complete mess !

 

I tried howler, and soundjs, and ended up settling for the cut-down verison of soundjs that has been included in the recent openFL release. It plays OGG if supported, and then MP3 if available - it still fails to play correctly on some android browsers (and any attempt to load a .ogg file on Windows Opera breaks it too) - but i recon it gives about 95% audio coverage.  (it still fails on the default android browser - but even mousedown events are broken on that browser, so i doubt many people use it given the alternatives)

 

I''ve been thinking that the best way is probably not to exclude certain useragents - but to work the opposite way ! - assume sound is disable, and only enable it when a known working useragent is detected ! (although haven't yet created a list of working configurations)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...