I'm trying to decode a stream to bitmap so I can pass it through an imageview to play a stream.
Alternative 1:
I have based it on this StackOverflow question: How to load an ImageView by URL in Android? [closed]
taking what I thought I needed, but when I run the App by calling I ca Funcion()
n't show the image.
What am I doing wrong? I have taken the equivalent functions of java
para xamarin
, the objects and others coincide so, I don't understand if my code or the stream is wrong or...
In my case I have tried to use several retransmissions taken from different places. Youtube, twitch, some television that broadcasts live or a local IP where I see stream through http.
private void Funcion()
{
ImageView image = FindViewById<ImageView>(Resource.Id.vView);
Bitmap stream = Task.Run(() => doInBackground()).Result;
image.SetImageBitmap(stream);
}
protected Bitmap doInBackground()
{
Bitmap stream;
stream = BitmapFactory.DecodeStream(new Java.Net.URL("URL").OpenStream());
return stream;
}
This is the view I use
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
tools:showIn="@layout/activity_main">
<ImageView
android:layout_width="500dp"
android:layout_height="500dp"
android:background="#ffffff"
android:id="@+id/vView" />
</RelativeLayout>
He
OnCreate()
only has the basics:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.activity_main);
Funcion();
}
The code has no more.
Alternative 2
Use
VideoView
:
VideoView video = FindViewById<VideoView>(Resource.Id.vView);
video.SetVideoURI(Android.Net.Uri.Parse("http://ip:puerto/"));
video.RequestFocus();
video.Prepared += delegate
{
video.Start();
};
This option seems the simplest to me, but when I start I get a dialog in which it tells me: ** The video cannot be played.** And that's the end of it.
http
If I enter from the browser with http://ip:port/ and inspect the element, what I see is this:
<Body>
<img style="-webkit-user-select: none;" src="http://ip:puerto/">
</Body>
I have found a solution for this, as the stream can be seen from any browser I have chosen to use it
WebView
to be able to view the "stream", which actually seems to be a sequence of images and deny the zoom and movements of thewebview
so that it looks like a video .C# code:
Axml: