Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 81910 articles
Browse latest View live

Is possible to use Xam.Plugins.Messaging in Xamarin.forms?

$
0
0

Hi ,
in my project need to send mail ,I'm using CrossPlatform IOS PCL ,When Im Trying to implement Xam.pluging.Messaging I'm getting following error
" Warning: Attempt to present on whose view is not in the window hierarchy!"


LayoutOptions Explained

$
0
0

Can someone describe or point me to documentation that explains the LayoutOptions? I'm not understanding how the Start, End, Center, Center and Expand, Start and Expand, Fill and Expand etc. works..

Thanks in advance

Missing References in UWP when installing Xamarin Forms Maps

$
0
0

If you install Xamarin Forms Maps (last stable version) with Nu Get Console and you restore Nu Get Packages then I find this missing (Yellow triangle) references in my UWP Project :

<SDKReference Include="Bing.Maps.Xaml, Version=1.313.0825.0">
  <Name>Bing Maps for C#, C++, or Visual Basic</Name>
</SDKReference>
<SDKReference Include="Microsoft.VCLibs, Version=12.0">
  <Name>Microsoft Visual C++ 2013 Runtime Package for Windows</Name>
</SDKReference>

Why ? Am I the only one ?

(Android) OnAppearing not raised when the page is child of a TabbedPage

$
0
0

I have a TabbedPage with two children pages: PageA and PageB, and PageA is the current page.

If I push another page and then I navigate back (pop), the OnAppearing() method of the PageA is not called in Android, but it is in iOS.

Any idea? How can I force it?

Thanks.

how to capture scroll screen in android...please help me..?

$
0
0

how to capture scroll screen in android...please help me..? or how to screen shoot all scroll pages in android?

Creating a new GestureRecognizer

$
0
0

Looking at the Xamarin.Forms Api tha you provide, there is only TapGestureRecognizer. I was thinking of implementing more GestureRecognizers. However, in the interface that you guy provide is

using System;
using System.ComponentModel;

namespace Xamarin.Forms
{
public interface IGestureRecognizer : INotifyPropertyChanged
{
}
}

Any more information that I missing on how to implement a new GestureRecognizer.

Note: I will post it to github once ready.

Microsoft.Identity.Client on iOS issues

$
0
0

Hi,

Not sure if this is the right forum for this conversation, however, when attempting to use the Microsoft.Identity.Client package on a Xamarin Forms iOS project, I am getting a Null Reference Exception.

My code is:

public class App : Application
{

    // app coordinates 
    public static string ClientID = "xx-xx-xx-xx";

public static string Authority = "https://login.microsoftonline.com/tenant.onmicrosoft.com/";

    public static PublicClientApplication PCApplication { get; set; }

    public App()
    {


        PCApplication = new PublicClientApplication(Authority, ClientID);

}

}

The exact exception is:

System.TypeInitializationException: The type initializer for 'Microsoft.Identity.Client.Internal.PlatformPlugin' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object

This happens as soon as the PublicClientApplication constructor is called.

Is anyone using Microsoft.Identity.Client in a Xamarin Forms project and knows of any issues with specific versions? Or know if how they're constructing the PublicClientApplication is different to the above? I've contacted the NuGet owners of Microsoft.Identity.Client as well..

How to open PDF in xamarin.forms?

$
0
0

How to open PDF in xamarin.forms?


ListView Sizing UWP

$
0
0

Hi,

on Android and iOS ListView automatically fills the remaining space in the view, no matter if enough items are present to fill it or not. In UWP ListView height depends on how many items are present in the collection it is bound to, when it is first created.
My ListView is bound to an observable collection which is empty in the beginning and gets filled by the user, on UWP as a result the height of the ListView is always zero when the app gets started the first time. Additions to the bound observable collection do not trigger a resizing of the the View.

I tried to set the LayoutOptions of the ListView and parent StackLayout to "FillAndExpand" but that doesn't change anything either. How can I set the ListView on UWP to fill the remaining height or trigger a resizing after the bound collection is modified?

Thank you

Xamarin.Forms Bindable Picker

$
0
0

If anyone wonders how to make a Bindable Picker, here's the code:

`

public class BindablePicker : Picker
{
    #region Fields

    //Bindable property for the items source
    public static readonly BindableProperty ItemsSourceProperty =
        BindableProperty.Create<BindablePicker, IEnumerable>(p => p.ItemsSource, null, propertyChanged: OnItemsSourcePropertyChanged);

    //Bindable property for the selected item
    public static readonly BindableProperty SelectedItemProperty =
        BindableProperty.Create<BindablePicker, object>(p => p.SelectedItem, null, BindingMode.TwoWay, propertyChanged: OnSelectedItemPropertyChanged);

    #endregion

    #region Properties

    /// <summary>
    /// Gets or sets the items source.
    /// </summary>
    /// <value>
    /// The items source.
    /// </value>
    public IEnumerable ItemsSource
    {
        get { return (IEnumerable)GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }

    /// <summary>
    /// Gets or sets the selected item.
    /// </summary>
    /// <value>
    /// The selected item.
    /// </value>
    public object SelectedItem
    {
        get { return GetValue(SelectedItemProperty); }
        set { SetValue(SelectedItemProperty, value); }
    }

    #endregion

    #region Methods

    /// <summary>
    /// Called when [items source property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnItemsSourcePropertyChanged(BindableObject bindable, IEnumerable value, IEnumerable newValue)
    {
        var picker = (BindablePicker)bindable;
        var notifyCollection = newValue as INotifyCollectionChanged;
        if (notifyCollection != null)
        {
            notifyCollection.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    foreach (var newItem in args.NewItems)
                    {
                        picker.Items.Add((newItem ?? "").ToString());
                    }
                }
                if (args.OldItems != null)
                {
                    foreach (var oldItem in args.OldItems)
                    {
                        picker.Items.Remove((oldItem ?? "").ToString());
                    }
                }
            };
        }

        if (newValue == null) 
            return;

        picker.Items.Clear();

        foreach (var item in newValue)
            picker.Items.Add((item ?? "").ToString());
    }

    /// <summary>
    /// Called when [selected item property changed].
    /// </summary>
    /// <param name="bindable">The bindable.</param>
    /// <param name="value">The value.</param>
    /// <param name="newValue">The new value.</param>
    private static void OnSelectedItemPropertyChanged(BindableObject bindable, object value, object newValue)
    {
        var picker = (BindablePicker)bindable;
        if (picker.ItemsSource != null)
            picker.SelectedIndex = picker.ItemsSource.IndexOf(picker.SelectedItem);
    }

    #endregion
}

`

Usage is pretty straight forward..:

<local:BindablePicker ItemsSource="{Binding Cats}" SelectedItem="{Binding SelectedCat}"/>

It would've been nice that the Xamarin.Forms.Picker already had this functionality, maybe we'll see it in a next update...

Any questions, comments, or contributions are welcome :)

Unable to update UI controls on UWP app after scanning with ZXing.Net

$
0
0

Hello Xamarin Forums,

I recently created a cross platform project in Visual Studio 2015 for Xamarin Forms. The purpose is to have a very simple barcode scanning app (just display the scanned barcode somewhere). For barcode scanning I use ZXing.Net.Mobile and ZXing.Net.Mobile.Forms.

The Windows App calls Xamarin Forms from the MainPage:

namespace UniveralWindowsApp
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage
    {
        public MainPage()
        {
            this.InitializeComponent();
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Portrait;

            ZXing.Net.Mobile.Forms.WindowsUniversal.ZXingScannerViewRenderer.Init();            

            // add this line
            LoadApplication(new XamarinFormsTestShared.App());
        }
    }
}

Android Activity to start Xamarin Forms

namespace XamarinFormsTestShared.Droid
{
    [Activity (Label = "XamarinFormsTestShared", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
    public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            global::Xamarin.Forms.Forms.Init (this, bundle);

            global::ZXing.Net.Mobile.Forms.Android.Platform.Init();

            LoadApplication (new XamarinFormsTestShared.App ());
        }
    }
}

I didn't make any changes to the Forms App:

namespace XamarinFormsTestShared
{
    public class App : Application
    {
        public App ()
        {
            MainPage = new NavigationPage(new HomePage());
        }

        protected override void OnStart ()
        {
            // Handle when your app starts
        }

        protected override void OnSleep ()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume ()
        {
            // Handle when your app resumes
        }
    }
}

Basically all my added code is in the HomePage ContentPage.

namespace XamarinFormsTestShared
{
    public class HomePage : ContentPage
    {        
        public HomePage()
        {            
            var buttonScan = new Button
            {
                Text = "Scan something!",
            };
            var label = new Label
            {
                Text = "This is where the barcode shoud go."
            };
            buttonScan.Clicked += async delegate
            {                
                var barcode = await GetBarcode();                
                Device.BeginInvokeOnMainThread(() =>
                {
                    // Gets here.
                    Debug.WriteLine("Try to update label.");
                    // This works on Android, not on Windows 10 Mobile.
                    label.Text = $"Barcode : {barcode}";
                });                
            };

            var stack = new StackLayout();            
            stack.Children.Add(label);
            stack.Children.Add(buttonScan);
            Content = stack;
        }

        private async Task<string> GetBarcode()
        {            
            var scanner = new MobileBarcodeScanner
            {
                UseCustomOverlay = false                
            };
            var result = await scanner.Scan();
            // This works.
            Debug.WriteLine($"Scanned barcode = {result.Text}");
            return result.Text;
        }        
    }
}

The problem is that this code works fine on Android yet not on my device with Windows 10 Mobile. I can scan barcodes on both platforms but after scanning is complete changing the Label's text has no effect in the Windows app. If I leave out scanning and just change the label text to a fixed value then the label does get updated! So it must have something to do with the call to the scanner. Any ideas how I can solve this?

ThingSpeak integration

$
0
0

Hi, I have Xamarin forms, I am finding problem to integrate ThinkSpeak cloud system. Please advise if any Nuget packages available to integrate with ThinkSpeak Cloud System

Border Radius and Border on Entry

$
0
0

Is there a way to set a border radius or border color/width on an Entry?

Or does that have to be done using custom renderers, and if so, does anyone have an example of what that would look like?

Problem with navigation from Windows native page back to Xamarin page.

$
0
0

Hi people,

i have a project that involves Windows universal project. Besides the shared project i have a windows universal and a Windows universal component project(the whole ides workflow is here). There is a problem when in the component project i need to go back (using the Form.goback() ) at the beginning in the Xamarin start page, and there is an exception with description ""No installed components were detected.\r\n\r\n Element is already the child of another element". I did not find any solutions on this. Can someone help?

Object reference not set to an instance of an object stacklayout.children.add

$
0
0
void  CargarImagenes()
        {
                stac.Children.Clear ();

                var directoryName = DependencyService.Get<IPicture> ().DirectorioImagenes ();
                var listaImage = clsoptioncamara.CargarFotos (directoryName);
                //listaImagenes.ItemsSource =   listaImage;
                stac.Children.Count();
                ObservableCollection<FileImageSource> files = new ObservableCollection<FileImageSource> ();
                foreach (var item in listaImage) {
                    files.Add (new FileImageSource{ File = item });
                }

                foreach (var items in files) {


                    var tapGestureRecognizer = new TapGestureRecognizer ();
                    tapGestureRecognizer.Tapped += (s, e) => {

                        imgImagen.Source = items;
                    };



                    imagenes = new Image (){ Source = items, WidthRequest = 200, HeightRequest = 200, Aspect = Aspect.AspectFill };
                    imagenes.GestureRecognizers.Add (tapGestureRecognizer);
                    stac.Children.Add (imagenes);

                }
 }

Project won't build: Xamarin.Android.Support

$
0
0

When creating a blank app (Xamarin.Forms Portable) using VS2015, when I attempt to build the project, the compiler complains about Xamarin.Android.Support repository r22.zip not being able to download, and to manually place it in my Android.Support.Design folder. I have tried following other topics on this form and stackoverflow, but to no avail. The project refuses to build.

When I attempt to install the packages off the nuget manager, I get an error that 23.0.1 doesn't support package111.

I have installed every single package available off the Android SDK Manager, and have tried setting the compiler to use the latest version of Android.

Any help would be appreciated. Thank you.

Severity    Code    Description Project File    Line
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.Design\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.Design\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\classes.jar doesn't exist.  XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\libs/internal_impl-23.0.1.jar doesn't exist.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v4' available in SDK installer. Android resource directory C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v4\23.0.1.3\embedded\./ doesn't exist.  XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3 directory.   XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.AppCompat' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3\embedded\classes.jar doesn't exist.  XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3 directory.   XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.AppCompat' available in SDK installer. Android resource directory C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.AppCompat\23.0.1.3\embedded\./ doesn't exist.  XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.CardView\23.0.1.3 directory.    XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.CardView' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.CardView\23.0.1.3\embedded\classes.jar doesn't exist.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.CardView\23.0.1.3 directory.    XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.CardView' available in SDK installer. Android resource directory C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.CardView\23.0.1.3\embedded\./ doesn't exist.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.MediaRouter' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\classes.jar doesn't exist.  XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.MediaRouter' available in SDK installer. Java library file C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\libs/internal_impl-23.0.1.jar doesn't exist.    XamarinFormsExample.Droid       
Error       Download failed. Please download https://dl-ssl.google.com/android/repository/android_m2repository_r22.zip and put it to the C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3 directory. XamarinFormsExample.Droid       
Error       Reason: One or more errors occurred.    XamarinFormsExample.Droid       
Error       Please install package: 'Xamarin.Android.Support.v7.MediaRouter' available in SDK installer. Android resource directory C:\Users\warrenbr\AppData\Local\Xamarin\Android.Support.v7.MediaRouter\23.0.1.3\embedded\./ doesn't exist.  XamarinFormsExample.Droid       

Activity indicator over StackLayout

$
0
0

Hi,

I want to show an activity indicator centered and over a StackLayout/Picker when the Listview is populated. How can i do that?

Everything is working fine with the StackLayout/Picker and the Listview but i don't know how to do it for the activity indicator...

Here is some code for my Stacklayout :

        sl = new StackLayout();
        sl.Children.Add(catPicker);
        sl.Children.Add(listView);
        sl.VerticalOptions = LayoutOptions.FillAndExpand;

Thanks!

XF Android : Could not load assembly Microsoft.Windows.Design.Extensibility

$
0
0

Hello ,
I have update Xamarin.Forms to 2.0.0.6490,
But get this exception when compile:

Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Microsoft.Windows.Design.Extensibility, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Perhaps it doesn't exist in the Mono for Android profile?
文件名:“Microsoft.Windows.Design.Extensibility.dll”
在 Xamarin.Android.Tuner.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
在 Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
在 Xamarin.Android.Tasks.ResolveAssemblies.Execute() UWPTest.Droid

Use Xamarin.Forms 2.0.0.6484 not has this question.
What happened ? Need I references it to Android Project ?

Thanks.

Problem creating Custom Renderer

$
0
0

Good Morning,

I have a problem and I don't know how to solve it. I am working with Custom Renderers in a Xamarin Form Project with the target to modify the behavior of a ScrollView:

public class ScrollViewCustomRenderer : ScrollViewCustom
{
float StartX, StartY;
int IsHorizontal = -1;

    protected override void OnElementChanged(ElementChangedEventArgs<Entry> e )
    {
        base.OnElementChanged(e);
        if (((Xamarin.Forms.ScrollView)e.NewElement).Orientation == ScrollOrientation.Horizontal) IsHorizontal = 1;

    }

    public override bool DispatchTouchEvent(MotionEvent e)
    {

        switch (e.Action)
        {
            case MotionEventActions.Down:
                StartX = e.RawX;
                StartY = e.RawY;
                this.Parent.RequestDisallowInterceptTouchEvent(true);
                break;
            case MotionEventActions.Move:
                if (IsHorizontal * Math.Abs(StartX - e.RawX) < IsHorizontal * Math.Abs(StartY - e.RawY))
                    this.Parent.RequestDisallowInterceptTouchEvent(false);
                break;
            case MotionEventActions.Up:
                this.Parent.RequestDisallowInterceptTouchEvent(false);
                break;
        }

        return base.DispatchTouchEvent(e);
    }
}

The problems are:
1.OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Xamarin.Forms.ScrollView>)': no suitable method found to override.
2. Error 39 'Xamarin.Forms.Element' does not contain a definition for 'RequestDisallowInterceptTouchEvent' and no extension method 'RequestDisallowInterceptTouchEvent' accepting a first argument of type 'Xamarin.Forms.Element' could be found (are you missing a using directive or an assembly reference?)

I have installed the last Xamarin.Forms references.

Many thanks,
Regards

Video Not Showing on Adroid both on Actual device and Emulator

$
0
0

I have problem with Android MediaPlayer its only playing Audion from an online video url not showing the video. Here is my renderer

public class VideoPlayerViewRender : ViewRenderer<VideoPlayer,VideoView> ,ISurfaceHolderCallback,MediaController.IMediaPlayerControl, MediaPlayer.IOnPreparedListener
{

    public VideoPlayerViewRender ()
    {
    }

    public void SurfaceChanged (ISurfaceHolder holder, global::Android.Graphics.Format format, int width, int height)
    {
        player.SetDisplay (holder );
    }

    public void SurfaceDestroyed (ISurfaceHolder holder)
    {

    }

    protected override void OnElementChanged (ElementChangedEventArgs<VideoPlayer> e)
    {
        base.OnElementChanged (e);
        e.NewElement.StopAction = () => {
            this.player.Stop ();
            this.Control.StopPlayback ();
        };
        e.NewElement.StopAction = () =>
        {
            this.player.Start();
        };


        videoview = new VideoView (Context);

        base.SetNativeControl (videoview);
        Control.Holder.AddCallback (this);
        Control.SetZOrderMediaOverlay(true);
        player = new MediaPlayer ();
        player.SetOnPreparedListener(this);
        controller = new MediaController(this.Context);
        play (e.NewElement.FileSource, Context);

    }

    VideoView videoview;
    MediaPlayer player;
    MediaController controller ;
    void play (string fullPath, Android.Content.Context context)
    { 

        if (fullPath != null) {

             var uri = Android.Net.Uri.Parse (fullPath);
            player.SetDataSource (Context, uri);
            player.Prepare ();
            //videoview.SetVideoURI(uri);
            player.Start ();
            Control.Layout (0, 200, player.VideoHeight,player.VideoWidth);
            //player.Pause ();
        }
    }
    public override bool OnTouchEvent(MotionEvent e)
    {
        controller.Show();
        return false;
    }

    //--MediaPlayerControl methods----------------------------------------------------
    public void Start()
    {
        player.Start();
    }


    public void Pause()
    {
        player.Pause();
    }

    public int Duration
    {
        get
        {
            return player.Duration;
        }
    }

    public int CurrentPosition
    {
        get
        {
            return player.CurrentPosition;
        }
    }

    public void SeekTo(int i)
    {
        player.SeekTo(i);
    }

    public bool IsPlaying
    {
        get
        {
            return player.IsPlaying;
        }
    }

    public int BufferPercentage
    {
        get
        {
            return 0;
        }
    }

    public int AudioSessionId
    {
        get
        {
            return 0;
        }
    }

    public bool CanPause()
    {
        return true;
    }

    public bool CanSeekBackward()
    {
        return true;
    }

    public bool CanSeekForward()
    {
        return true;
    }

    public void SurfaceCreated (ISurfaceHolder holder)
    {
        player.SetDisplay (holder);
    }
    public  void OnPrepared(MediaPlayer mediaPlayer)
    {
        controller.SetMediaPlayer (this);
        controller.SetAnchorView (videoview);

    }

}
Viewing all 81910 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>