Skip to content

Commit

Permalink
fix: audio start & multiple android app
Browse files Browse the repository at this point in the history
  • Loading branch information
manatlan committed Nov 14, 2023
1 parent 1962086 commit 675c88e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions htag/runners/androidapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@
from htag.render import HRenderer
from . import commons

import os,json,asyncio
import os,json,asyncio,socket

import tornado.ioloop
import tornado.web
import tornado.platform.asyncio

from threading import Thread

def isFree(ip, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
return not (s.connect_ex((ip,port)) == 0)

class WebServer(Thread): # the webserver is ran on a separated thread

def __init__(self,instance,port):
Expand Down Expand Up @@ -88,7 +93,10 @@ def go_exit(self):
self._exiter()

def run(self): # basically, the same code as guy.runAndroid()
host,port= "127.0.0.1", 12458
host= "127.0.0.1"
port = 12458
while not isFree(host,port):
port+=1
urlStartPage = f"http://{host}:{port}"

self.server = WebServer(self,port)
Expand Down Expand Up @@ -146,8 +154,13 @@ def exit_app(*a,**k):
@run_on_ui_thread
def create_webview(self, *args):
webview = webView(activity)
webview.getSettings().setJavaScriptEnabled(True)
webview.getSettings().setDomStorageEnabled(True)
webSettings=webview.getSettings()
webSettings.setJavaScriptEnabled(True)
webSettings.setDomStorageEnabled(True)
try:
webSettings.setMediaPlaybackRequiresUserGesture(False) # SDK_INT > 17
except:
pass
webview.setWebViewClient(webViewClient())
activity.setContentView(webview)
webview.loadUrl(urlStartPage) # !important
Expand Down

0 comments on commit 675c88e

Please sign in to comment.