语言

Menu
Sites
Language
how to use Tizen Player with Xamarin Forms?

Hello to everyone, i want to create an application with xamarin forms to display a video, but as i see in the documentation is necesary to create a custom render in xamarin based on the VisualElementRenderer class, but i couldn't find any documentation or guide of how to implement the custom render, someone could help me with this one?  

based on this documentation:
https://developer.tizen.org/development/guides/.net-application/media-and-camera/media-playback?langredirect=1 

响应

1 回复
Tizen .NET

Hi,
I'm sorry for the inconvenience caused by insufficient documentation.
Here are some resource to reference about custom renederer.
1. Xamarin.Forms Custom Renderers- https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/
2. Sample app and sample codes 
 - Sample app - https://github.com/Samsung/Tizen-CSharp-Samples/tree/master/Wearable/CircularUIMediaPlayer/src
 - MediaView - https://github.com/Samsung/Tizen.CircularUI/blob/master/src/Tizen.Wearable.CircularUI.Forms/MediaView.cs
 - MediaViewRenderer - https://github.com/Samsung/Tizen.CircularUI/blob/master/src/Tizen.Wearable.CircularUI.Forms.Renderer/MediaViewRenderer.cs

And here is a part of sample code about MediaView and MediaViewRenderer.

public interface IMediaViewController
{
    void SendNativeViewCreated();
}

public class MediaView : View, IMediaViewController
{
    public event EventHandler NativeViewCreated;

    public object NativeView
    {
        get; private set;
    }

    void IMediaViewController.SendNativeViewCreated()
    {
        NativeViewCreated?.Invoke(this, EventArgs.Empty);
    }

    public void SetNativeView(object obj)
    {
        NativeView = obj;
    }
}
[assembly: ExportRenderer(typeof(MediaView), typeof(MediaViewRenderer))]
namespace MediaTest
{
    public class MediaViewRenderer : ViewRenderer<MediaView, Tizen.Multimedia.MediaView>
    {
        Tizen.Multimedia.MediaView _view;

        protected override void OnElementChanged(ElementChangedEventArgs<MediaView> e)
        {
            _view = new Tizen.Multimedia.MediaView(Xamarin.Forms.Platform.Tizen.Forms.NativeParent);
            SetNativeView(_view);
            Element.SetNativeView(_view);

            (Element as IMediaViewController)?.SendNativeViewCreated();

            base.OnElementChanged(e);
        }
    }
}
public class PlayerService
{
    Player _player;

    public PlayerService()
    {
        _player = new Player();
    }

    public Task PrepareAsync()
    {
        return _player.PrepareAsync();
    }

    public void Start()
    {
        _player.Start();
    }

    public void Stop()
    {
        _player.Stop();
    }

    public void Unprepare()
    {
        _player.Unprepare();
    }

    public void SetSource(string file)
    {
        var uri = "file://" + Path.Combine(Program.ResourceDir, file);
        _player.SetSource(new MediaUriSource(uri));
    }

    public void SetDisplay(MediaView view)
    {
        if(view.NativeView is Tizen.Multimedia.MediaView tmv)
        {
            _player.Display = new Display(tmv);
        }
    }
}

If you have any further questions, please contact us,
Thank you.