I have an app that plays a youtube video when a proper link is given. Problem is, the app uses what is probably a native player that overrides the youtube one. Here is my current code:
if (newsVideo != "" && isConnected == true)
{
myWebView = FindViewById<WebView>(Resource.Id.NewsVideo);
int intDisplayHeight;
var screenwidth = metrics.WidthPixels;
intDisplayHeight = screenwidth / 2;
string convertednewsVideo = newsVideo.Replace("=\"\\", "=\\");
List<string> newsVideoLink = VideoParseHTML.ReturnVideoUrl(convertednewsVideo);
foreach (string item in newsVideoLink)
{
string strUrl = item.Substring(1, item.Length - 2);
string html = #"<html><body><iframe src=""strUrl"" width=""100%"" height=""videoHeight"" frameborder=""0"" ></iframe></body></html>";
var settings = myWebView.Settings;
settings.JavaScriptEnabled = true;
settings.UseWideViewPort = true;
settings.LoadWithOverviewMode = true;
settings.JavaScriptCanOpenWindowsAutomatically = true;
settings.DomStorageEnabled = true;
settings.SetRenderPriority(WebSettings.RenderPriority.High);
settings.BuiltInZoomControls = false;
settings.AllowFileAccess = true;
settings.SetPluginState(WebSettings.PluginState.On);
myWebView.SetWebChromeClient(new WebChromeClient());
string strYouTubeURL = html.Replace("videoHeight", intDisplayHeight.ToString()).Replace("strUrl", strUrl);
myWebView.LoadData(strYouTubeURL, "text/html", "UTF-8");
}
}
This is what the player looks like:
What I want is either force the application to use the youtube player or if that isn't possible, to at least remove the fullscreen button from the native player, as I don't want this functionality.
Thank you
Related
I am trying to send the camera stream from unity to an RTCPeerConnection in the browser. The signaling between the two peers is done correctly, although when I send the MediaStreamTrack it does not work in the browser. Does anybody have an idea? This is similar to Unity.RenderStreaming, but I am trying to build my own. Here's the code I use for accessing the camera and sending the track.
//Create local peer
RTCConfiguration config = default;
config.iceServers = new[] { new RTCIceServer { urls = new[] { "stun:stun.l.google.com:19302" } } };
localConnection = new RTCPeerConnection(ref config);
localConnection.OnNegotiationNeeded = () => { Debug.Log("negotiation needed"); StartCoroutine(handleNegotiationNeeded()); };;
localConnection.OnIceCandidate += handleIceCandidate;
localConnection.OnIceConnectionChange = handleIceConnectionChange;
RenderTexture rt;
if (arCamera.targetTexture != null)
{
rt = arCamera.targetTexture;
RenderTextureFormat supportFormat = WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
GraphicsFormat graphicsFormat = GraphicsFormatUtility.GetGraphicsFormat(supportFormat, RenderTextureReadWrite.Default);
GraphicsFormat compatibleFormat = SystemInfo.GetCompatibleFormat(graphicsFormat, FormatUsage.Render);
GraphicsFormat format = graphicsFormat == compatibleFormat ? graphicsFormat : compatibleFormat;
if (rt.graphicsFormat != format)
{
Debug.LogWarning(
$"This color format:{rt.graphicsFormat} not support in unity.webrtc. Change to supported color format:{format}.");
rt.Release();
rt.graphicsFormat = format;
rt.Create();
}
arCamera.targetTexture = rt;
}
else
{
RenderTextureFormat format = WebRTC.WebRTC.GetSupportedRenderTextureFormat(SystemInfo.graphicsDeviceType);
rt = new RenderTexture(1270, 720, 0, format)
{
antiAliasing = 1
};
rt.Create();
arCamera.targetTexture = rt;
}
track = new VideoStreamTrack(rt);
Debug.Log(rt.format);
Debug.Log(track.Texture.graphicsFormat);
Debug.Log(track.IsEncoderInitialized);
localConnection.AddTrack(track);
Debug.Log("track added");
The full code can be found here
https://github.com/MohammedShetaya/AR_Video_Straming/blob/main/Assets/Scripts/WSClient.cs
yes it is possible, but it is quite difficult, and beyond the scope of a SO answer. Check out this Unity Package for some help: https://docs.unity3d.com/Packages/com.unity.webrtc#2.4/manual/index.html
Is there a way you can detect in C# if a browser is blocking external marketing
tracking information like fbq?
In JQuery you can use typeof fbq !== 'undefined' to detect if the Facebook Pixel tracking code is blocked, For example:
if(typeof fbq !== 'undefined'){
fbq('track', 'ViewContent', {
value: FacebookPriceIncVat,
currency: FacebookInitiateCheckoutCurrency,
content_ids: FacebookSKUView,
content_type: 'product',
});
}
I have one module in which the Facebook Tracking code can only be generated on the back-end. Is there a way you can detect if fbq exist using perhaps ajax that changes a bool or some other way to detect if something is blocking links in your browser like a plugin of some sort?
The code below should not execute if fbq is not present.
if (FacebookPixelID != null)
{
EndUserFirstName = SessionManager.CurrentUserInfo.FirstName;
EndUserLastName = SessionManager.CurrentUserInfo.LastName;
EndUserEmail = SessionManager.CurrentUserInfo.UserName;
FacebookInitializationCodeID = FacebookPixelID;
string FacebookPixelResult = string.Empty;
using (var FBPxl = new StringWriter())
using (var FBCodescript = new HtmlTextWriter(FBPxl))
{
FBCodescript.AddAttribute(Attr.Type, "text/javascript");
FBCodescript.RenderBeginTag(Tag.Script);
//load ecommerce plugin
FBCodescript.WriteLine("!function(f,b,e,v,n,t,s){if (f.fbq) return; n = f.fbq = function(){n.callMethod?n.callMethod.apply(n, arguments):n.queue.push(arguments)};");
FBCodescript.WriteLine("if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0';");
FBCodescript.WriteLine("n.queue =[]; t = b.createElement(e); t.async = !0;");
FBCodescript.WriteLine("t.src = v; s = b.getElementsByTagName(e)[0];");
FBCodescript.WriteLine("s.parentNode.insertBefore(t, s)}");
FBCodescript.WriteLine("(window, document,'script','https://connect.facebook.net/en_US/fbevents.js');");
FBCodescript.WriteLine($"fbq('init', '{FacebookInitializationCodeID}', {{ em: '{EndUserEmail}', fn: '{EndUserFirstName}', ln: '{EndUserLastName}',}});");
FBCodescript.WriteLine("fbq('track', 'PageView');");
FBCodescript.RenderEndTag();
FBCodescript.WriteLine($"<noscript><img height='1' width='1' style='display:none' src='https://www.facebook.com/tr?id={FacebookInitializationCodeID}&ev=PageView&noscript=1'/></noscript>");
FacebookPixelResult = FBCodescript.InnerWriter.ToString();
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "myFacebookPixelInitialization", FacebookPixelResult, false);
//Facebook Pixels Purchase Code
string FacebookPixelPurchase = string.Empty;
if (RevenueCurrency != null)
{
FBPurchaseCurrency = RevenueCurrency;
}
else
{
FBPurchaseCurrency = "ZAR";
}
using (var FBPxlPurchase = new StringWriter())
using (var FBCodescriptPurchase = new HtmlTextWriter(FBPxlPurchase))
{
FBCodescriptPurchase.AddAttribute(Attr.Type, "text/javascript");
FBCodescriptPurchase.RenderBeginTag(Tag.Script);
//Write Facebook Pixel Purchase Event code
FBCodescriptPurchase.WriteLine("fbq('track', 'Purchase', {");
FBCodescriptPurchase.WriteLine($"value: {trans.Revenue},");
FBCodescriptPurchase.WriteLine($"currency: '{FBPurchaseCurrency}',");
FBCodescriptPurchase.WriteLine($"content_ids: '{string.Join(",", trans.LineItems.Select(l => l.SKU).ToArray())}',");
FBCodescriptPurchase.WriteLine("content_type: 'product',");
FBCodescriptPurchase.WriteLine($"contents: [");
var PurchaseCounter = 1;
foreach (var lineitem in trans.LineItems)
{
FBCodescriptPurchase.WriteLine("{");
FBCodescriptPurchase.WriteLine($"id: '{lineitem.SKU}',");
FBCodescriptPurchase.WriteLine($"quantity: {lineitem.Quantity},");
FBCodescriptPurchase.WriteLine($"item_price: {lineitem.UnitPrice}");
FBCodescriptPurchase.WriteLine("}");
if (PurchaseCounter != trans.LineItems.Count) FBCodescriptPurchase.WriteLine(",");
PurchaseCounter++;
}
FBCodescriptPurchase.WriteLine("]");
FBCodescriptPurchase.WriteLine("});");
FBCodescriptPurchase.RenderEndTag();
FacebookPixelPurchase = FBCodescriptPurchase.InnerWriter.ToString();
}
Page.ClientScript.RegisterStartupScript(this.GetType(), "myFacebookPixelPurchase", FacebookPixelPurchase, false);
}
}
I think it is actually easy to fix this.
Don't know why I did not think of this.
I can just add the if statement in the C# code.
I am trying to capture the screen in IOS, Other than WkWebview all other view component I am able to capture by below code.WkWebview is giving a blank page as captured data. If I am using UIWebview the same code working Is there anything specific to do to take screen shot WkWebView.
Code for screen capture.
public static UIImage SnapshotView(this UIView view)
{
UIGraphics.BeginImageContextWithOptions(view.Bounds.Size, false, UIScreen.MainScreen.Scale);
view.DrawViewHierarchy(view.Bounds, true);
var image = UIGraphics.GetImageFromCurrentImageContext();
UIGraphics.EndImageContext();
return image;
}
WkWebView Configuration:
WKWebView _wkWebView = new WKWebView(ReaderView.Frame, new WKWebViewConfiguration());
_wkWebView.LoadFileUrl(tempUrl, tempUrl);
_wkWebView.ContentMode = UIViewContentMode.ScaleToFill;
_wkWebView.BackgroundColor = UIColor.Clear;
_wkWebView.Opaque = false;
_wkWebView.ScrollView.BackgroundColor = UIColor.Clear;
//_wkWebView.DrawViewHierarchy(_wkWebView.Bounds, true);
ReaderView.AddSubview(_wkWebView);
var imag = _wkWebView.SnapshotView();
I fixed the issue by replacing the WKWebView with PdfView.I am using this view for loading PDFs.
The latest code is below
pdfView = new PdfView();
pdfView.TranslatesAutoresizingMaskIntoConstraints = false;
ReaderView.AddSubview(pdfView);
pdfView.LeadingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.LeadingAnchor).Active = true;
pdfView.TrailingAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TrailingAnchor).Active = true;
pdfView.TopAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.TopAnchor).Active = true;
pdfView.BottomAnchor.ConstraintEqualTo(View.SafeAreaLayoutGuide.BottomAnchor).Active = true;
// var path = Bundle.main.url(forResource: "test", withExtension: "pdf") else { return }
PdfDocument document;
// PdfDocument
using (urlString = new NSString(FilePath))
using (var tempUrl = NSUrl.CreateFileUrl(new string[] { urlString }))
document = new PdfDocument(tempUrl);
//if var document = PdfDocument(url: path) {
pdfView.Document = document;
When I launch my game in game editor or on the phone - it glitches for the 2-3 seconds and calls the function OnApplicationPause. But when I close application/pause in editor it doesn't calls. That's bad for my project so how to fix it? There's function code :
void OnApplicationPause()
{
DateTime time = DateTime.Now;
SaveVariablesInClass();
PlayerPrefs.SetString("SV", JsonUtility.ToJson(save)); //saves special class
}
void SaveVariablesInClass()
{
save.Bananas = bananas;
save.GoldBananas = goldBananas;
save.TwoBananasSpawnChance = twoBananasSpawnChance;
save.HigherBananaLevelChance = higherBananaLevelChance;
save.SimpleBananaStormChance = simpleBananaStormChance;
save.GoldBananaChance = goldBananaChance;
save.TwoGoldBananaChance = twoGoldBananaChance;
save.offlineEfficiency = offlineEfficiency;
save.offlineProductionTime = offlineProductionTime;
save.goldCoefficient = goldCoefficient;
save.BonusLevels = bonusLevels;
save.GoldBonusLevels = goldBonusLevels;
save.SimpleBonusLevelPrices = simpleBonusLevelPrices;
save.GoldBonusLevelPrices = goldBonusLevelPrices;
save.simpleMaxLevels = simpleMaxLevels;
save.goldMaxLevels = goldMaxLevels;
save.time = time.ToString();
save.CurrentSimpleBonus1 = currentSimpleBonus1;
save.LaunchedGame = launchedGame;
}
You are missing the bool parameter in the method. It should be OnApplicationPause(bool pauseStatus). OnApplicationPause is called on each GameObject after Awake. So your code should be:
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
DateTime time = DateTime.Now;
SaveVariablesInClass();
PlayerPrefs.SetString("SV", JsonUtility.ToJson(save)); //saves special class
}
}
The lag you show in comments is caused by rendering not script.
I would like to run youtube videos in a media element. This morning, everything worked well but now I have an error saying that an object is null. I've tried to find the object but there is not. An other group has the same case as mine. I didn't change anything.
private async void runYoutubeVideo(String youtubeId)
{
try
{
Console.WriteLine(youtubeId);
var url = await YouTube.GetVideoUriAsync(youtubeId, YouTubeQuality.Quality480P);
_mediaElementObject.Source = url.Uri;
_modelPlayer.CurrentMedia = new Media(url.Uri, YoutubeURLString);
TitleFile = _modelPlayer.CurrentMedia.FileName;
YoutubeURLString = null;
Uri tmp = new Uri(_modelPlayer.CurrentMedia.FilePath);
this._mediaElementObject.Source = tmp;
this.SliderVideoObject = 0;
createTimerTrick();
_mediaElementObject.Play();
}
catch
{
Console.WriteLine("Youtube Runner Error");
new NullReferenceException("Error");
return;
}
}