Quantcast

Callbaks, how to use.

classic Classic list List threaded Threaded
8 messages Options
Ken
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Callbaks, how to use.

Ken
MediaPlayer have a few callbacks, one is SetOnPreparedListener. In java code I see the use like _mp.SetOnPreparedListener(this) but I can't use that in C#.

How do I use the callback, code example please.

http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Anthonymwheeler
Stop!!!! I no longer wish to receive your email from this domain period!

Sent from my iPhone

On Apr 22, 2011, at 2:44 PM, Ken <[hidden email]> wrote:

> MediaPlayer have a few callbacks, one is SetOnPreparedListener. In java code
> I see the use like _mp.SetOnPreparedListener(this) but I can't use that in
> C#.
>
> How do I use the callback, code example please.
>
> http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html
>
>
>
> --
> View this message in context: http://mono-for-android.1047100.n5.nabble.com/Callbaks-how-to-use-tp4333558p4333558.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> [hidden email]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Anthonymwheeler
In reply to this post by Ken
Stop!!!! I no longer wish to receive your email from this domain period!

Sent from my iPhone

On Apr 22, 2011, at 2:44 PM, Ken <[hidden email]> wrote:

> MediaPlayer have a few callbacks, one is SetOnPreparedListener. In java code
> I see the use like _mp.SetOnPreparedListener(this) but I can't use that in
> C#.
>
> How do I use the callback, code example please.
>
> http://developer.android.com/reference/android/media/MediaPlayer.OnPreparedListener.html
>
>
>
> --
> View this message in context: http://mono-for-android.1047100.n5.nabble.com/Callbaks-how-to-use-tp4333558p4333558.html
> Sent from the Mono for Android mailing list archive at Nabble.com.
> _______________________________________________
> Monodroid mailing list
> [hidden email]
>
> UNSUBSCRIBE INFORMATION:
> http://lists.ximian.com/mailman/listinfo/monodroid
_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Jonathan Pryor
In reply to this post by Ken
On Apr 22, 2011, at 2:44 PM, Ken wrote:
> MediaPlayer have a few callbacks, one is SetOnPreparedListener. In java code
> I see the use like _mp.SetOnPreparedListener(this) but I can't use that in
> C#.

Do you have a larger example context in mind? MediaPlayer.SetOnPreparedListener(MediaPlayer.IOnPreparedListener) requires that the parameter implement the MediaPlayer.IOnPreparedListener interface. If `this` implements the required interface, then it too should work in C#. I imagine that your reference Java code is implementing the MediaPlayer.OnPreparedListener interface, and your ported C# code hasn't implemented that interface yet.

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Ken
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Ken
Hi,

I'm used to use events in C# so that's why I'm not clear on how to do this.

Here is some more java code, code on row# 193 and # 341 is what I'm need in
C#:
https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/p
honegap/AudioPlayer.java

/Ken

-----Ursprungligt meddelande-----
Från: [hidden email]
[mailto:[hidden email]] För Jonathan Pryor
Skickat: den 25 april 2011 04:34
Till: Discussions related to Mono for Android
Ämne: Re: [mono-android] Callbaks, how to use.

On Apr 22, 2011, at 2:44 PM, Ken wrote:
> MediaPlayer have a few callbacks, one is SetOnPreparedListener. In
> java code I see the use like _mp.SetOnPreparedListener(this) but I
> can't use that in C#.

Do you have a larger example context in mind?
MediaPlayer.SetOnPreparedListener(MediaPlayer.IOnPreparedListener) requires
that the parameter implement the MediaPlayer.IOnPreparedListener interface.
If `this` implements the required interface, then it too should work in C#.
I imagine that your reference Java code is implementing the
MediaPlayer.OnPreparedListener interface, and your ported C# code hasn't
implemented that interface yet.

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1209 / Virus Database: 1500/3594 - Release Date: 04/24/11

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Greg Shackles
For that you could follow the exact same style in C#. "this" refers to an instance of AudioPlayer, which implements the OnPreparedListener interface (or IOnPreparedListener in C#). You can see that declared on line 28 and implemented on line 341. Doing this in C# would look something like:

public class Activity1 : Activity, Android.Media.MediaPlayer.IOnPreparedListener
{
  protected override void OnCreate(Bundle bundle)
  {
    base.OnCreate(bundle);

    var player = new Android.Media.MediaPlayer();
    player.SetOnPreparedListener(this);
  }

  public void OnPrepared(MediaPlayer mp)
  {
  }
}

I used an Activity there just as a quick example, but you could use the same approach for any class.

On Mon, Apr 25, 2011 at 5:22 AM, Kennet Andhersån <[hidden email]> wrote:
Hi,

I'm used to use events in C# so that's why I'm not clear on how to do this.

Here is some more java code, code on row# 193 and # 341 is what I'm need in
C#:
<a href="https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/p honegap/AudioPlayer.java" target="_blank">https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/p
honegap/AudioPlayer.java

/Ken

-----Ursprungligt meddelande-----
Från: [hidden email]
[mailto:[hidden email]] För Jonathan Pryor
Skickat: den 25 april 2011 04:34
Till: Discussions related to Mono for Android
Ämne: Re: [mono-android] Callbaks, how to use.

On Apr 22, 2011, at 2:44 PM, Ken wrote:
> MediaPlayer have a few callbacks, one is SetOnPreparedListener. In
> java code I see the use like _mp.SetOnPreparedListener(this) but I
> can't use that in C#.

Do you have a larger example context in mind?
MediaPlayer.SetOnPreparedListener(MediaPlayer.IOnPreparedListener) requires
that the parameter implement the MediaPlayer.IOnPreparedListener interface.
If `this` implements the required interface, then it too should work in C#.
I imagine that your reference Java code is implementing the
MediaPlayer.OnPreparedListener interface, and your ported C# code hasn't
implemented that interface yet.

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid



-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 10.0.1209 / Virus Database: 1500/3594 - Release Date: 04/24/11

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid


_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Jonathan Pryor
In reply to this post by Ken
On Apr 25, 2011, at 5:22 AM, Kennet Andhersån wrote:
> I'm used to use events in C# so that's why I'm not clear on how to do this.

Unfortunately, we're not currently able to map interface members to events. You thus need to implement the interface yourself.

> Here is some more java code, code on row# 193 and # 341 is what I'm need in C#:
> https://github.com/phonegap/phonegap-android/blob/master/framework/src/com/phonegap/AudioPlayer.java

Greg Shackles provided an example, but please note that whenever you implement an Android interface, you must also subclass Java.Lang.Object (directly or indirectly). The com.phonegap.AudioPlayer type would thus be declared in C# as:

        public class AudioPlayer : Java.Lang.Object
                        , MediaPlayer.IOnCompletionListener
                        , MediaPlayer.IOnPreparedListener
                        , MediaPlayer.IOnErrorListener
        {
                // implement interfaces here...
        }

 - Jon

_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Ken
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Callbaks, how to use.

Ken
Thanks! Works fine.

/Ken

Loading...