惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
News and Events Feed by Topic
GbyAI
GbyAI
博客园 - Franky
宝玉的分享
宝玉的分享
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
腾讯CDC
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
I
InfoQ
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Engineering at Meta
Engineering at Meta
MongoDB | Blog
MongoDB | Blog
有赞技术团队
有赞技术团队
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Full Disclosure
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Vercel News
Vercel News
博客园 - 【当耐特】
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
S
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Project Zero
Project Zero
量子位
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
美团技术团队
Attack and Defense Labs
Attack and Defense Labs
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Troy Hunt's Blog
Google Online Security Blog
Google Online Security Blog
罗磊的独立博客
P
Proofpoint News Feed
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
S
SegmentFault 最新的问题
L
LINUX DO - 最新话题
Simon Willison's Weblog
Simon Willison's Weblog
爱范儿
爱范儿
博客园 - 聂微东
A
About on SuperTechFans
PCI Perspectives
PCI Perspectives
D
Docker

oida.dev | TypeScript, Rust

TypeScript's `erasableSyntaxOnly` Flag Unsafe for work Tokio: Macros Tokio: Channels Tokio: Getting Started Network Applications on the Tokio Stack Remake, Remodel, Reduce. The `never` type and error handling in TypeScript 5 Inconvenient Truths about TypeScript Refactoring in Rust: Introducing Traits Refactoring in Rust: Abstraction with the Newtype Pattern Announcing the TypeScript Cookbook TypeScript: Iterating over objects The road to universal JavaScript 10 years of oida.dev Rust: Tiny little traits The TypeScript converging point How not to learn TypeScript Getting started with Rust Introducing Slides and Coverage TypeScript: The humble function overload TypeScript + React: Children types are broken TypeScript: In defense of any Rust: Enums to wrap multiple errors Dissecting Deno Error handling in Rust TypeScript: Unexpected intersections Upgrading Node.js dependencies after a yarn audit TypeScript: Array.includes on narrow types TypeScript + React: Typing Generic forwardRefs shared, util, core: Schroedinger's module names Learning Rust and Go TypeScript: Narrow types in catch clauses TypeScript: Low maintenance types Tidy TypeScript: Name your generics Tidy TypeScript: Avoid traditional OOP patterns Tidy TypeScript: Prefer type aliases over interfaces Tidy TypeScript: Prefer union types over enums My new book: TypeScript in 50 Lessons Go Preact! ❤️ this in JavaScript and TypeScript TypeScript and ECMAScript Modules TypeScript + React: Why I don't use React.FC TypeScript + React: Component patterns TypeScript: Augmenting global and lib.dom.d.ts Vite with Preact and TypeScript TypeScript: Union to intersection type 11ty: Generate Twitter cards automatically Are large node module dependencies an issue? TypeScript: Variadic Tuple Types Preview TypeScript: Improving Object.keys Remake, Remodel. Part 4. TypeScript + React: Typing custom hooks with tuple types TypeScript: Assertion signatures and Object.defineProperty TypeScript: Check for object properties and narrow down type Boolean in JavaScript and TypeScript void in JavaScript and TypeScript Symbols in JavaScript and TypeScript Why I use TypeScript TypeScript + React: Extending JSX Elements TypeScript: Validate mapped types and const context TypeScript: Match the exact object shape TypeScript: The constructor interface pattern Streaming your Meetup - Part 4: Directing and Streaming with OBS Streaming your Meetup - Part 3: Speaker audio Streaming your Meetup - Part 2: Speaker video Streaming your Meetup - Part 1: Basics and Projector TypeScript and React Guide: Added a new styles chapter TypeScript and React Guide: Added a new render props chapter TypeScript and React: Styles and CSS TypeScript and React TypeScript and React Guide: Added a new prop types chapter TypeScript without TypeScript -- JSDoc superpowers TypeScript: Mapped types for type maps JAMStack vs serverless web apps The Unsung Benefits of JAMStack Sites TypeScript: Ambient modules for Webpack loaders My most favourite talks in 2018 TypeScript and React Guide: Added a new context chapter TypeScript: Built-in generic types TypeScript: Type predicates JSX is syntactic sugar TypeScript and React Guide: Added a new hooks chapter Getting your CfP application right FAQ on our Angular Connect Talk: Automating UI development TypeScript and Substitutability Debugging Node.js apps in TypeScript with Visual Studio Code From Medium: Deconfusing Pre- and Post-processing From Medium: PostCSS misconceptions Saving and scraping a website with Puppeteer Cutting the mustard - 2018 edition Wordpress as CMS for your JAMStack sites My most favourite podcast episodes in 2017 My most favourite talks in 2017 My most favourite books in 2017 The Best Request Is No Request, Revisited Not so hidden figures - Organizing ScriptConf My podcast journey to ScriptCast Grid layout, grid layout everywhere! #scriptconf and #devone
HTML5 Audio on mobile devices
2012-04-08 · via oida.dev | TypeScript, Rust

HTML5 Audio on desktop browsers is a mess. But you haven't experienced true pain and suffering until you try to get HTML5 audio done on mobile devices. This article is a follow-up to my talk at the Barcamp in Salzburg in March and was inspired by Chris Heilmans tweets on that topic a few days ago.

First of all: We all know Modernizr, we all use it and we all love it. With Modernizr we made a huge step away from applying features by browser detection towards feature detection. This is not only the recommended way of building websites and web-apps, but even more a mindset or way of thinking: Ask your browser what it can do (do a test), and you know what you can use, absolutely independent of browser vendors and versions.

For such a complex feature like HTML5 Audio, it's great that with areweplayingyet there is a community out there which supplies such tests for HTML5 Audio subfeatures, API calls and best practices like hot swapping audio sources.

If you run through some tests and view the browser compatibilty list, you will see that many tests fail on mobile browsers like early Android implementations and especially on iOS devices. But why? Is HTML5 Audio compatibility really that bad on iPad and iPhone, especially when it's the only way to include sound?

Well. Yes and no. HTML5 Audio is pretty f***ed up on iOS too, but it works. And if you know the rules, you know why all tests fail and how you can deal with that.

#1 - One does not simply play sound on JS event

The most important rule of all: Do not think that you just can play sound by using JS events, like you're used to when working with Desktop browsers. Each sound playing requires a user interaction, their "OK" or their "Go for it" by touching an element on your page. This can be the built-in Audio player controls (which seem to be not compliant to Apples user interface standards by being flipping small), or any click or touch eventhandler bound to your elements. Once an interaction is done, the file is downloaded to your device. After that, you can do all the cool audio things you want to do.

But why do you need user interaction to play audio (and video)? Isn't that unusual? Might be, but imagine yourself with your iPhone in a roaming region, having limited bandwidth, trying to reach your favourite website which just came up with some nifty 10MB background song not only trying to ruin your nerves, but also adding some more bucks on your phone bill for next month. User interaction seems legit now.

Possible solution for that: Have a splash screen in your app, that the user has to remove, and that triggers the download of your soundfile. Quirky and awful, but so far the only way at the moment.

#2 - There can be only one!

Classy old Immortal rule: You can't play more than one sound file at once. So no background music and laser buzzes in your star shooter. Personally I'm okay with that. But how about making use of that? Think of "There should be only one!". Enter sound sprites.

Image sprites are well known: Having one image with all icons and stuff, and accessing them by putting the right background-position in your CSS file. Sound sprites work similar: Put all sound you want to play in one audio file, and define start and ending indices. Now the workflow is as follows:

  • User removes splash screen, downloads file
  • A few seconds of silence are played, right at the start and right after interaction
  • After that, we should have direct access to all positions in the whole file. Just jump to your positions as you like

Below is some sprite demo I came up with in my talk, but also take a look at Chris' more sophisticated solution.

<audio src="sprite.mp3" controls="none" id="myaudio" />
var maudio = document.getElementById('myaudio');

var soundSprite = [
  {start: 0, end: 3000},
  {start: 3500, end: 6789}
];

element.addEventListener('touchstart', function(ev) {
  maudio.play();
  playSoundFile(0);
})

function playSoundFile(idx) {
  maudio.currentPosition = soundSprite[idx].start;
  var x = setInterval(function() {
    if(maudio.currentPosition >= soundSprite[idx].end) {
      maudio.pause(); // There is no stop() in HTML5
      clearInterval(x);
    }
  }, 50);
}

Soundsprites are pretty common now, and well supported by libraries like SoundManager2.

Think back to Modernizr: We now know that iOS devices support HTML5 Audio, we know that we can do a lot with that even if the tests fail. Can you adapt your tests? Is it okay to have the user interact with your app before testing? Is it okay to download test files? Or do you just go back to user agent sniffing to wrap up your target platforms?

Internet Explorer 9 Mobile

The things learned above apply to most mobile Webkit implementations, but we have to deal with another browser as well: IE9 on mobile devices

IE9 doesn't support a lot HTML5/CSS3 features, but the features that it supports are usually really well implemented and robust. Same goes for HTML5 Audio, which also has been stated by the developers of Cut the rope in a blog post some months ago.

Same goes for the mobile version of Internet Explorer 9. And usually, you can expect everything that works in IE9 will also work in IE9 mobile. Same goes for sound, we even don't have to wait for user interaction when playing and downloading files! Although I don't know if that's a good thing or a bad one.

However, there's one thing that doesn't work on IE9 Mobile, and that is changing your sound "position" when playing, so sound sprites won't work there. Now imagine a web-app exclusively covering IE9 mobile and iOS, I wonder how tests are going to look like there, or if you just go back to user agent sniffing.

Bottom line: HTML5 Audio is a wreck at the moment, and don't get fooled by "support". Just because your devices supports a certain feature does not mean that it's usable in the way you are used to.

Related Articles