ludei / webview-plus

Uniform webview on any Android 4.x device.
103 stars 16 forks source link

No audio on start in Webview and Webview+. Works in Canvas. #11

Closed agamemnus closed 10 years ago

agamemnus commented 10 years ago

(This is in the launcher. I'm on Android 4.4.2, Note 2. The compiled APK gives no sound at all. I tried both mp3 and ogg.)

Including this and the latest cocoon.min.js:

void function () {
 CocoonJS.Audio = function () {return this}
 CocoonJS.Audio.prototype = {
  audio    : null,
  setAudio : function (audio) {this.audio = audio; this.audio.load(); return this},
  loop     : function (loop) {return this},
  play     : function () {this.audio.volume = 0.5; this.audio.play(); return this},
  pause    : function () {this.audio.pause(); return this}
 }
} ()

void function () {
 CocoonJS.Music = function () {return this}
 CocoonJS.Music.prototype = {
  audio    : null,
  setAudio : function( audio ) {
   this.audio = audio
   this.audio.load()
   this.audio.addEventListener ('ended', function (audioEvent) {audioEvent.target.playing = false; console.log("Audio ends playing.")}, false)
   return this
  },
  loop     : function () {
   if (!this.audio) {console.log ("audio not present."); return}
   this.audio.loop = !this.audio.loop
   return this
  },
  play     : function () {if (!this.audio) {console.log ("audio not present."); return}
   if (this.audio.playing) return
   this.audio.playing = true
   this.audio.play ()
   return this
  },
  pause    : function () {
   if (!this.audio) {console.log ("audio not present."); return}
   this.audio.pause ()
   this.audio.playing = false
   return this
  }
 }
} ()

function play_music () { 
 var testaudio = new Audio(); testaudio.src = "resources/musics/music.ogg"
 testaudio.type = "audio/ogg"
 var cjs_music = new CocoonJS.Audio()
 cjs_music.setAudio (testaudio)
 testaudio.oncanplay = function () {
  cjs_music.play ()
 }
}

play_music ()
setTimeout (function () {play_music ()}, 3000)

document.body.style.width  = "500px"
document.body.style.height = "500px"
document.body.style.backgroundColor = "green"
document.body.addEventListener ('click', play_music)
document.body.addEventListener ('touchend', play_music)

No audio on start or in 3s, only on click.

ludei commented 10 years ago

After some time investigating this issue, here are some conclusions:

So I believe that this is something on the side of Chromium, Canvas+ uses its own audio implementation, so that's why it is working in that environment. Can't figure out when this issue will be fixed, we'll be aware of any update of the chromium project that may solve this issue.

Cheers

agamemnus commented 10 years ago

But... it works (I mean, audio in general, not the test case, since it mentions window.CocoonJS, obviously) in my Chrome Android browser, which is 36.0.1985.128. I don't see how it can be Chromium...

Is it possible that you have volume set to 0? (even though, yes, it is .5 in your wrapper, but that may not be getting through...?)

Why does audio work in the launcher? (except for "audio on start", which doesn't work in the launcher)

ludei commented 10 years ago

About volume set to 0... is not the case. I had high volume.

CocoonJS Launcher uses the same rendering libraries as the cloud compiler, the result of a compilation made in the cloud compiler should be exactly the same running in CocoonJS Launcher.

In order to clarify this issue, and knowing that is a Chrome issue. What do you need to fix this issue?

agamemnus commented 10 years ago

@_@

I am very confused!

When I said volume was set to 0 I meant some sort of intermediate volume setting was inadvertenly set to 0, perhaps, not the system volume.

What do I need to fix this issue? I don't know, I'm not the one developing Webview+ and I don't have the Java source code. :-)

So, to recap: 1) In Webview+ and Webview, sound does not run without a touch event in both the launcher and the compiled apk... pretty important issue. 2) In Webview+ (Webview is fine, didn't test CANVAS!), on my Note 2 with Android 4.4.2, sound (which starts on touch events) runs only in the 2.0.2 launcher and it does not run in the cloud compiler. 3) My app plays audio from the phone's Chrome browser on touch. I have the 36.0.1985.128 Chrome Android browser.

agamemnus commented 10 years ago

I think this may be the same bug and possibly the reason why audio plays in the launcher -- different URLs.

http://code.google.com/p/chromium/issues/detail?id=387898

This doesn't explain why audio doesn't run without a click/touch event, however. Was this meant to be implemented in Webview+?

agamemnus commented 10 years ago

Hmm.

Maybe we need a prefix for local files, e.g. /android_asset/game/ or /android_asset/www/?

ludei commented 10 years ago

This issue is related to this other issue: https://code.google.com/p/chromium/issues/detail?id=387898

The Chromium team has recently solved this problem. We'll include the fix in one of the next releases of the Webview+.

olegkalichak commented 10 years ago

Hi. I represent the web development company. We are developing the game using Webview+ runtime, so this is very important for us. Can you clarify the date of new release with this fix? (at least the approximate date)

agamemnus commented 10 years ago

olegkalichak, meanwhile you can try building just with Cordova-Crosswalk, at least for Android. If you add a file in (for example) /platforms/android/assets/ called xwalk-command-line you can add command line options. One of them is --disable-gesture-requirement-for-media-playback which seems to be extremely recent. So just do (for example):

xwalk --disable-gesture-requirement-for-media-playback

:-D

Here is mine in full:

xwalk --disable-gesture-requirement-for-media-playback --use-mobile-user-agent --enable-begin-frame-scheduling --enable-fixed-position-compositing --enable-threaded-compositing --enable-accelerated-overflow-scroll --enable-overlay-fullscreen-video --in-process-gpu --disable-gpu-shader-disk-cache --enable-viewport --enable-viewport-meta --main-frame-resizes-are-orientation-changes --disable-composited-antialiasing --ui-prioritize-in-gpu-process --enable-delegated-renderer --profiler-timing=0 --prerender=auto --disable-gpu-watchdog --supports-dual-gpus=true --gpu-driver-bug-workarounds=1,8,43,45 --canvas-msaa-sample-count=0 --disable-low-res-tiling --disable-overlay-scrollbars

txusinho commented 10 years ago

@olegkalichak the release is expected for the next week the latest.