Autoplaying audio in a Webview (iOS)

ios

#1

This tutorial looks great tutorial - can’t wait to try it with a project.
Do you know how it will cope with audio in the hype document ?
When I have used Phone Gap in the past I’ve always got stuck on the audio.


Embed a Tumult Hype document in a Webview for publishing on the iOS App Store
(kerguelen) #2

I was wondering, with this method, is it possible to make apps with media auto trigger ? I know that user action is need d to play a sound when a Hype document is played within a browser on a mobile device, but is it still the case for an app built with your solution ?


#3

Maybe someone else is better equipped to answer this, but you may need to set a ‘NO’ value for this property: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIWebView_Class/#//apple_ref/occ/instp/UIWebView/mediaPlaybackRequiresUserAction


(Nick ) #4

Yes and No
Yes you can get the audio to import as part of your Hype.html file into Xcode and it plays if you initiate the action to play sound. Clicking a button for example.
No extra OBJ C to write to make that happen.
For instance the attached Hype doc has the audio load as an On Scene Load action but since it is an HTML5 file ultimately Apple has a No auto load HTML video or audio policy.

What I am wondering is if…

  1. you created an element (a box) made it invisible.
  2. Have it move to another invisible element detect the collision and “play sound”

Yes that is a hack BUT it might just work it would appear as an auto play and could be integrated into a intro animation. Kind of like a hidden circuit in the app :wink:
If anyone else wants to have a go with it feel free and let me know. I will also try.

audiotest.hype.zip (234.2 KB)


(Jean Robert Thibault) #5

Hi

Long time ago, it was possible to send a MouseDown in MacroMedia Director. I whish we could do that in Hype.

So in opening a scene, such message would simulate an autoPlay and so play background sounds in iDevices.

Would’t that be great! If it was possible 20 years ago, why not now!

JR


(Nick ) #6

@alastair,@daniel,@kerguelen,@Monteverdi,
SOLVED!! :smile:

I have spent some more time diving into this issue and I believe there is an answer albeit not an HTML5 answer.
Apple has blocked any HTML5 auto play for awhile on mobile iOS which we all know. The official reason is that they felt it would be a drain on the mobile carriers bandwidth if everyone could stream audio and video from web pages.

There is a way to override the autoplay ban but you need to adjust your Xcode file in order to do that.
AND IT IS SUPER SIMPLE.
You just need to add the line in your view controller.m file
self.Webview.mediaPlaybackRequiresUserAction = NO;

View the screenshot below to see where it is added in the .m file
I will add another How to Video on my channel to show Hype to Xcode with autoplay over the weekend.

Cheers!
Nick


Embed a Tumult Hype document in a Webview for publishing on the iOS App Store
Xcode/iTunesConnect has lost audio on app
Sound Effects over IOS Music app
#7

@daniel,@kerguelen,@Monteverdi

Nick - audio in my app, embedded in hype, is working perfectly, but it plays as alert sound rather than system audio. In other words, if alerts are muted on the iPad or iPhone, you don’t hear it.

I’m not quite sure why this is - possibly the way I triggered it in hype with javascript linked to buttons or possible a setting in Xcode.

Do you have any thought on this ? As the app is mainly audio, I need to get it right before I think of submitting to Apple.

Alastair


#8

Replying to my own post here - Some apps play sound with the ringer off, some don’t.

When you bring a hype project in as a web view, it seems the ringer needs to be on to play audio.

In some Phone Gap apps I have seen, it works whichever way the ringer switch is set, however I don’t think this is a major issue.


(Nick ) #9

Yes one thing about XCode is everything is like a series of switches. You have to make sure all the right settings are applied one by one.
Are you still having trouble with it or has it been resolved?


(alastairnisbet) #10

The audio (from Hype) only plays when the ringer on the iPad is on - but that goes for other apps too, so I don’t think it is particularly an issue do you ?

Alastair


(Nick ) #11

Man, I just saw this so sorry…
Yes you have to have the ringer turned on. there might be a deeper way to override the switch but I have not stumbled on it yet.


(alastairnisbet) #12

Hi Nick - yes resolved. It’s working pretty well on the iPad, but I have yet to get the screen to resize properly for different devices. I’m hoping to get it on the app store but I know they are very fussy !

Alastair


(Nick ) #13

They are and they are’nt just make sure you use the most recent conventions and all of your icon art is setup properly.
The adjustable size using Hype layouts has not translated for me yet.
I am trying some conversions with SWIFT so I’ll keep you posted.


(alastairnisbet) #14

Thanks Nick - I’ll let you know how I get on. The app currently has an external web link for uploading comments and pictures which they probably won’t like. I have used a Google font which I need to rasterise into the graphics, but on the plus side it is very simple !

Alastair


(Aleksander) #15

Hi Nick,

I can put a code directly with Hype to fix the problem without use Xcode?

Fuv


(Nick ) #16

Not sure I understand or are you asking if you can
create AutoPlay on an exported HTML5 file on an iOS device?

If that is the question I would say no.
Apple still has not allowed the use of AutoPlay for HTML5 based projects.
Mobile Safari has essentially disabled auto play and will not recognize it.

You have to put in a user “tap” touch event to launch it.