I have a small application. I am opening youtube in webview and see the videos.
Everything is good but when I click the video it is opening new page and start video automaticly full screen.
I do not want auto start play video.
How can I do it?
My code:
let conf = WKWebViewConfiguration()
conf.allowsInlineMediaPlayback = false //Tried and Did not work
conf.requiresUserActionForMediaPlayback = true //Tried and Did not work
super.init(frame: CGRect.zero, configuration: conf)
Try it conf.allowsInlineMediaPlayback = true .
Related
An error is reported when playing h5 audio or video elements in wkwebview: Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Required client entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"MediaPlayback" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required client entitlement is missing}>
Then the performance of the webview will become very poor, no response to any element click.This problem has affected our tens of thousands of users.The current solution is to call the client method to play audio.How to solve the problem fundamentally?
1.There is an audio element and a button button in my HTML file. Click the button to play audio.
<body>
<button onclick="handleClick()">PLAY</button>
<audio id="audio" src="https://ac-dev.oss-cn-hangzhou.aliyuncs.com/test-2022-music.mp3"></audio>
<script>
function handleClick() {
document.getElementById("audio").play();
}
</script>
</body>
2.Create a wkwebview to load the html file in my demo APP.
class ViewController: UIViewController , WKUIDelegate{
var webView: WKWebView!
override func loadView() {
let config = WKWebViewConfiguration()
config.preferences.javaScriptEnabled = true
config.allowsInlineMediaPlayback = true
webView = WKWebView(frame: .zero, configuration: config) //.zero
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "https://ac-dev.oss-cn-hangzhou.aliyuncs.com/test-2022-py.html")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
3.Click the button in the HTML to play the audio, and you can see the error report on the xcode.
iPadN[2133:855729] [assertion] Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=3 "Required client entitlement is missing" UserInfo={RBSAssertionAttribute=<RBSDomainAttribute| domain:"com.apple.webkit" name:"MediaPlayback" sourceEnvironment:"(null)">, NSLocalizedFailureReason=Required client entitlement is missing}>
4.To sum up, this error will appear when playing audio or video in HTML. Then the app performance will drop a lot, and the interactive response will be very slow.
I had a similar issue. My plan was to use new Audio(...) with an asset or a blob stored as object url in the storage. It is working for the asset but was not for the blob stored as string in the storage ... but only on the device, exactly like you mentioned.
I resolved it with the following strategy (for the not working part, it is all type script in my case, but can be done directly in java script):
create a ``AudioContext```
create ArrayBuffer from my blob/string using the ``FileReader```
decode the audio data (await context.decodeAudioData(arrayBuffer, (buffer) => {...}))
play the sound on the destination of the audio context:
const source = context.createBufferSource();
source.buffer = buffer;
source.connect(context.destination);
source.start(0)
clean up the stuff on end, if needed
source.onended = async(): Promise<void> => {
source.disconnect();
await context.close();
}
I am having an issue with Spotify preview links, they are not playing using AVPlayer.
var aSongURL: String = String(format: "https://p.scdn.co/mp3-preview/2d933f6474345c8af7e164356f30f450d0fc1309?cid=5e9ac4fc700442599e05f987a9cb1d4a")
var aPlayerItem: AVPlayerItem = AVPlayerItem(url: NSURL(string: aSongURL)! as URL)
var anAudioStreamer: AVPlayer = AVPlayer(playerItem: aPlayerItem)
anAudioStreamer.play()
It's a MP3, why is it not supported by AVPlayer, any ideas?
Try the method described here. It worked for me for your URL.
I'm trying to test that a file downloaded is initialized when i click on an image. So far i've been unable to find anything that seems to work with page object.
More specifically i'm looking for a way to handle the download dialogue pop up and to verify that file.exe has begun downloading.
Thank you
You can activate some option when you launch your browser. Here an example I use :
# create the folder location
download_directory = "#{Dir.pwd}/downloads/"
download_directory.gsub!("/", "\\") if Selenium::WebDriver::Platform.windows?
# Create the firefox profile
profile['browser.download.folderList'] = 2
profile['browser.download.dir'] = download_directory
profile['download.prompt_for_download'] = false
profile['browser.helperApps.neverAsk.saveToDisk'] = "application/octet-stream,text/csv,application/pdf"
profile['network.http.use-cache'] = false
# launch FF
#browser = Watir::Browser.new :firefox, profile: profile
Then you don't need to handle the window, but only to check the downloaded file in the folder you define.
For chrome, you can't use a profile, but should use preferences.
# Create the prefs
prefs = {
download: {
prompt_for_download: false,
default_directory: #download_directory
}
}
# Launch chrome
#browser = Watir::Browser.new :chrome, prefs: prefs
And no, I don't find a solution for internet explorer yet.
In my windows store app I used Windows.Media.Capture.CameraCaptureUI class to capture Images and Videos. The recorded videos are working fine in Windows environment. But the same recorded file is not played well in Ipad.
I will include the code here
CameraCaptureUI dialog = new CameraCaptureUI();
dialog.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
dialog.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.LowDefinition;
StorageFile capturedMedia = null;
if( _showVideo )
capturedMedia = await dialog.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);
else
capturedMedia = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);
Please help.
This looks more like a bug report. Sometimes there are bugs.
This is something you should report at http://connect.microsoft.com than here.
Your contribution to Connect helps other developers.
I'm using the below code (references from, http://www.java-tips.org/java-me-tips/midp/playing-video-on-j2me-devices.html). It fails at 'realize()', with the javax.microedition.media.MediaException, "Unable to create native player". What is the problem here?
I tried this using both Eclipse and Netbeans. Am I missing some "internet" permissions or using any incorrect encoding, the video is an external 'mpg' test-resource and does work fine when downloaded through a desktop browser.
public void run()
{
String url = "http://www.fileformat.info/format/mpeg/sample/05e7e78068f44f0ea748855ef33c9f4a/MELT.MPG";
//Append the GUI to a form
Form form = new Form("Video on java mobile!");
Display display = Display.getDisplay(this);
display.setCurrent(form);
try
{
HttpConnection conn = (HttpConnection)Connector.open(url,
Connector.READ_WRITE);
InputStream is = conn.openInputStream();
Player p = Manager.createPlayer(is,"video/mpeg");
//I tried the below, but that didn't work either
//Player p = Manager.createPlayer(url);
p.realize();
//Get the video controller
VideoControl video = (VideoControl) p.getControl("VideoControl");
if(video != null)
{
//Get a GUI to display the video
Item videoItem = (Item)video.initDisplayMode(
VideoControl.USE_GUI_PRIMITIVE, null);
form.append(videoItem);
}
//Start the video
p.prefetch();
p.start();
}
catch(Exception e)
{
form.append(url + " Error:" + e.getMessage());
}
}
I've just started with Java, Eclipse, Netbeans. Since, there similar samples found everywhere, I believe I'm missing something very basic. Can someone please help?
The problem here was the video file. Although my source video seemed "mpeg", it wasn't acceptable to the emulator. After searching through a bit, I found a converter and I manually converted some sample mp4 to "mpeg". It finally worked with the same emulator, after I tried to download and play these manually converted files.
One piece of advise if you are new J2ME/JavaME apps (like me), keep playing with the input data sources/formats and the emulators. Switching emulators or the input data-formats is an easy way to identify the not-so-evident problems.