XAMARIN - add video from youtube - c#

i search information how to add video from youtube, example:
I want add video from some youtube link.
I think that it should be in webview, but i need some details, because i can't find any information about my problem.

You can use the webview to play youtube video.
string html=#"<html><body><iframe width=""200"" height=""400"" src=""strUrl""></iframe></body></html>";
var myWebView = ( WebView ) FindViewById ( Resource.Id.myWebView );
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.JavaScriptCanOpenWindowsAutomatically=true;
myWebView.SetWebChromeClient(new WebChromeClient());
settings.AllowFileAccess = true;
settings.SetPluginState(WebSettings.PluginState.On);
myWebView.LoadDataWithBaseURL(null,html,"text/html","UTF-8",null);
Add internet permission in manifest file and enable hardwareAccelerated="true". Follow this my blog entry for more detail : http://appliedcodelog.blogspot.in/2015/09/how-to-play-youtube-video-using-webview.html

Update: Everything below is still correct, but the official YouTube API for Android is now available.
By far, the easiest way to play a YouTube video on Android is to simply fire an Intent to launch the native Android YouTube app. Of course, this will fail if you are not on a certified Google device, that doesn't have the complement of Google apps. (The Kindle Fire is probably the biggest example of such a device). The problem with this approach is that the user will not automatically wind up back at your app when the video finishes; they have to press the Back button, and at this point you've probably lost them.
As a second option, you can use the MediaPlayer API to play YouTube videos. But there are three caveats with this approach:
1) You need to make a call to YouTube's GData webservice API, passing it the ID of the video. You'll get back a ton of metadata, along with it the RTSP URL that you should pass to MediaPlayer to play back an H.264-encoded stream. This is probably the reason why your attempt to use MediaPlayer failed; you probably weren't using the correct URL to stream.
2) The GData/MediaPlayer approach will only play back low-resolution content (176x144 or similar). This is a deliberate decision on the part of YouTube, to prevent theft of content. Of course, this doesn't provide a very satisfactory experience. There are back-door hacks to get higher resolution streams, but they aren't supported on all releases of Android and using them is a violation of YouTube's terms of service.
3) The RTSP streams can be blocked by some internal networks/firewalls, so this approach may not work for all users.
The third option is to embed a WebView in your application. There two approaches you can take here:
1) You can embed a Flash object and run the standard desktop Flash player for YouTube. You can even use the Javascript API to control the player, and relay events back to the native Android app. This approach works well, but unfortunately Flash is being deprecated on the Android platform, and will not work for Android 4.1 and later.
2) You can embed a <video> tag to play YouTube via HTML5. Support for this varies between various releases of Android. It works well on Android 4.0 and later; earlier releases have somewhat spotty HTML5 <video> support. So, depending upon what releases of Android your application must support, you can take a hybrid approach of embedding HTML5 on Android 4.x or later, and Flash for all earlier versions of Android.
There are several threads here on StackOverflow about using HTML5 to play YouTube video; none of them really describe the entire process you must follow in one place. Here's links to a few of them:
Android - How to play Youtube video in WebView?
How to embed a YouTube clip in a WebView on Android
Play Youtube HTML5 embedded Video in Android WebView
All of this will get dramatically easier in the weeks/months to come; at Google I/O 2012, they presented/demoed a new YouTube API for Android that will support direct embedding of YouTube content in your application, with full support back to Android 2.2 (about 95% of the Android userbase as of this writing). It can't arrive fast enough.
Thanks #mportuesisf for this wonderful answer.

Heres some links.
http://docs.xamarin.com/recipes/android/media/video/play_video/
Streaming Youtube Videos

for xamarin forms you can use HtmlWebViewSource
in my VM:
public HtmlWebViewSource VideoSource { get; set; }
in constructor :
VideoSource = new HtmlWebViewSource();
VideoSource.Html = #"<html><body> <div style=' position: relative; padding-bottom: 56.25%; padding-top: 25px;'> <iframe style='position: absolute; top: 0; left: 0; width: 100%; height: 100%;' src='https://www.youtube.com/embed/bVdfj7HXuXE' frameborder='0' allowfullscreen></iframe></div> </body></html>";
in my View :
<WebView VerticalOptions="Fill"
HorizontalOptions="Fill"
Source="{Binding VideoSource}"
/>

firstly you must copy the link above the video youtube when you click on share then choose integrate and select the src of the youtube video
then in your c sharp create :
and you're gonna see the video inside the web view
WebView webview = FindViewById<WebView>(Resource.Id.webView1);
video =("the src of the youtube video");
var uri = Android.Net.Uri.Parse(video);
WebSettings settings = webview.Settings;
settings.JavaScriptEnabled = true;
webview.SetWebChromeClient(new WebChromeClient());
webview.LoadUrl(video);

Related

Is there any alternative to MediaStreamType.photo to get photo stream in winforms or WPF?

In UWP, to get photostream(not videostream), I use like below.
System.Collections.Generic.IReadOnlyList<IMediaEncodingProperties> res = this.mediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo);
await this.mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, res[0]);
However, I cannot find any alternative of it in winforms or WPF.
I keep trying to get photo not video snapshot from webcam.
Any comment will be helpful.
The api mediaCapture can be used from desktop app, see the api description page: https://learn.microsoft.com/en-us/uwp/api/Windows.Media.Capture.MediaCapture
You will find this attribute:DualApiPartitionAttribute
So to use UWP api from desktop app, see This Use UWP API in desktop app.

how can i play VLC live streaming video in asp.net application using HTML video Tag

I setup a live stream of the VLC Media player using Http and I want this stream to be played in my asp.net application using HTML 5 Video tag.
I expect to play the live stream of the VLC in my asp.net application.
First You need to supply the MIME type attribute in the video tag:
type="application/x-mpegURL". The video tag I use for a stream looks
like this.
<video width="352" height="198" controls>
<source src="VLCLiveStreamingURLGoesHere" type="application/x-mpegURL">
</video>
Make sure to replace VLCLiveStreamingURLGoesHere with your VLC Live stream URL.
If you want to play direct HLS file, then add chrome extension called Native HLS Playback from chrome web app.
A possible alternative for that:
Use an encoder (e.g. VLC or FFmpeg) into packetize your input stream
to OGG format. For example, in this case I used VLC to packetize
screen capture device with this code:
C:\Program Files\VideoLAN\VLC\vlc.exe -I dummy screen://
:screen-fps=16.000000 :screen-caching=100
:sout=#transcode{vcodec=theo,vb=800,scale=1,width=600,height=480,acodec=mp3}:http{mux=ogg,dst=127.0.0.1:8080/desktop.ogg}
:no-sout-rtp-sap :no-sout-standard-sap :ttl=1 :sout-keep
Embed this code into a tag in your HTML page like that:
This should do the trick. However it's kind of poor performance and
AFAIK MP4 container type should have a better support among browsers
than OGG.
HTML5 live streaming

How to play Flash videos with a Gecko WebBrowser? (GeckoFX)

I'm using the GeckoFX 'GeckoWebBrowser' user control to navigate but I can't play Flash videos of any page, for example if I try to navigate to youtube it always displays this error:
There is a way to enable Flash videos?
UPDATE:
I've set this property:
GeckoPreferences.Default("extensions.blocklist.enabled") = False
...And now the background of the videos are shown but I can't reproduce any video.
About the "Emoticon" who says that this video is unaivailbe : this is because the page is not showing properly so you can see all divisions what should be hidden in the page like you must enable JavaScript in your browser.
i had simmilar problems with GeckoFx my suggestion is moving to WEBKITDOTNET is the best for now as compenent
Here

Displaying youtube video in silverlight app using Javascript/jQuery

I'm converting an application from php/js/css over to c#/silverlight for a client.
In the old system, I used a URL & the jquery prettyPhoto plugin to display a youtube video.
In the new system, silverlight cannot play FLV natively.
Does anybody have a process & code for how to get my link from the silverlight app, over to a div in my aspx page hosting the silverlight control (default.aspx), then playing the video?
Cheers,
Scott
Lets say you have this Javascript function in your host .aspx page:-
function goAheadAndPlayThatVid(urlOfVid)
{
// some code that plays the Vid
}
Now in Silverlight/C# code you can invoke this function with:-
HtmlPage.Window.Invoke("goAheadAndPlayThatVid", "urlOfVidHere");

Youtube videos link in my own admin

Problem: client has lot's of videos. He uploads them to youtube. i've built a simple cms for him where he updates the content on the site. I would like to simplify the process of linking the videos within the cms.
Currently he has to
upload the video to youtube
"embeded" the youtube code in the cms.
is there a simpler? better solution? any suggestions would be very helpful.
Thanks in advance.
Shane
Have the client create a YouTube channel and create playlist(s) within that channel. Then the client can just tell you which playlist(s) to include on the site and you can pull in all the videos within specific playlists via the YouTube API.
This way you set it (once) and forget it. And the client can maintain the playlists within YouTube as they see fit and know that the videos within those playlists will be automatically included on the web site.
Here are some sample code snippets:
// Init service.
YouTubeService service = new YouTubeService("MyApplicationName", "MyDeveloperApiKey");
// Get playlists for youtube user (your client).
PlaylistsFeed playlists = service.GetPlaylists(new YouTubeQuery("http://gdata.youtube.com/feeds/api/users/[CLIENT_USER]/playlists"));
// Get playlist feed.
PlaylistFeed feed = service.GetPlaylist(new YouTubeQuery("http://gdata.youtube.com/feeds/api/playlists/" + playlistID)));
// Get list of video IDs for playlist.
(from atomEntry in feed.Entries select (atomEntry as PlaylistEntry).VideoId).ToList());
YouTube API integration ASP.NET - upload video with a single page

Categories

Resources