How add Kaltura sdk Player in iOS xamarin form


#1

I am working in Kaltura sdk to stream my videos.how can I integrate kaltura to xamarin form cross platform, could you help me with this situation?


#2

Hi @pruebas_testa,

Xamarin doesn’t have OOB swift binding, but this can be overcome by exporting us statically via the object bridge.
We haven’t tested it and haven’t intended to support this so we’re not certain it will work but you can give it a try.
Have a look at this guide:
https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/

There’s also this article which explains how to create a binding for Swift in Xamarin:

Good luck,


#3

Hi @jess

I already implemented the swift binding but it returns the following error when I am integrating the binding to the xamarin ios project

System.Exception: Could not create an native instance of the type ‘MediaSource’: the native class hasn’t been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
at Foundation.NSObject.InitializeObject (System.Boolean alloced)

could you give me a hand with this.


#4

hey @pruebas_testa,

Please make sure to use “PKMediaSource” not “MediaSource” with our latest version.

Best,
Eliza


#5

Hey @elizas,

I am using the binding the lastes versión, the source is PKMediaSource but when the binding is done the result is as follows.

[Protocol]
    [Register("MediaSource", true)]
    public class MediaSource : NSObject, IMediaSource, INativeObject, IDisposable
    {
        [CompilerGenerated]
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        [Export("init")]
        public MediaSource();
        [CompilerGenerated]
        [Export("initWithId:")]
        public MediaSource(string id);
        [CompilerGenerated]
        [DesignatedInitializer]
        [Export("initWithJson:")]
        public MediaSource(NSObject json);
        [CompilerGenerated]
        [DesignatedInitializer]
        [Export("init:contentUrl:mimeType:drmData:mediaFormat:")]
        public MediaSource(string id, NSUrl contentUrl, string mimeType, DRMParams[] drmData, MediaFormat mediaFormat);
        [CompilerGenerated]
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        protected MediaSource(NSObjectFlag t);
        [CompilerGenerated]
        [EditorBrowsable(EditorBrowsableState.Advanced)]
        protected internal MediaSource(IntPtr handle);

        public override IntPtr ClassHandle { get; }
        [CompilerGenerated]
        public virtual NSUrl ContentUrl { get; set; }
        [CompilerGenerated]
        public virtual string Description { get; }
        [CompilerGenerated]
        public virtual DRMParams[] DrmData { get; set; }
        [CompilerGenerated]
        public virtual string FileExt { get; }
        [CompilerGenerated]
        public virtual string Id { get; set; }
        [CompilerGenerated]
        public virtual MediaFormat MediaFormat { get; set; }
        [CompilerGenerated]
        public virtual string MimeType { get; set; }
    }

#6

Hey,

Can you share some sample that demonstrates the issue via Github and I will try to help you.
When uploading the sample please let us know what is the issue and what are the steps to reproduce.

Thanks,

Eliza

cc @oren_melamed


#7

@elizas thanks for your help, I share an example of the problem I have

project which has the binding for Swift frameworks to be able to use it in xamarin forms

xamarin form project, which uses the previously compiled SharpieSDK dll

in the project sdkIOSBinding a class was created with the name KalturaViewRenderer but when calling the method DoPublish () exactly the line

var entry = new MediaEntry (“test”, null, 5000),

always returns the error
System.Exception: Could not create an native instance

Thanks.


#8

@elizas on the other hand in android I have an issue which only happens in real device , which is reported in the following link

the java binding for xamarin form is this

when I add the BindingJar dll to the xamarin form android project.

in the OnElementChanged () method
when I execute the next line of code
player.Prepare (mediaConfig);

it returns me
{Java.Lang.NoSuchMethodError: No virtual method addListener(Lcom/google/android/exoplayer2/ExoPlayer$EventListener;)V in class Lcom/google/android/exoplayer2/SimpleExoPlayer; or its super classes (declaration of ‘com.google.android.exoplayer2.SimpleExoPlayer’ appears in /data/app/App9.Android-1/base.apk)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at Java.Interop.JniEnvironment+InstanceMethods.CallVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00069]

Thanks.


#9

please replace MediaEntry with PKMediaEntry


#10

@vadim.kononov if you can visualize in the ios binding code, when swift code converting to code c# this PKMediaEntry is renamed with MediaEntry, in a few words it is the same


#11

hi, @pruebas_testa
A new version is available, that should fix your issue


Best regards, Vadim


#12

best information great thank u


#13

Hi @vadim.kononov thanks for the feedback,

but I updated the version how you mention it and apparently it shows me a new error when compiling the cocopod, I attach the error in a text file.

Thanks.


#14

hi, @pruebas_testa
The error you are observing during compilation relates to swift version. I don’t know exactly how xamarin works with pods, but you should verify that you are compiling our sdk with swift 4 compiler
Vadim


#15

hi @vadim.kononov

finally I was able to compile the pods but again the issue of the native instance is returning me

{System.Exception: Could not create an native instance of the type ‘SharpieSDK.MediaEntry’: the native class hasn’t been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.
at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0003a] in //xamarin-macios/src/Foundation/NSObject2.cs:182
at Foundation.NSObject…ctor (Foundation.NSObjectFlag x) [0x0000d] in //source/xamarin-macios/src/Foundation/NSObject2.cs:117
at SharpieSDK.MediaEntry…ctor (System.String id, SharpieSDK.MediaSource[] sources, System.Double duration) [0x00000] in \SharpieSDK\obj\Debug\ios\SharpieSDK\MediaEntry.g.cs:187
at App8.iOS.OpenTokViewRenderer.DoPublish () [0x00002] in }


#16

thanks for the feedback but I finally decided to use the native player of each platform.