在gwt中使用phonegap音频api

发布于 2024-10-07 09:27:40 字数 254 浏览 8 评论 0原文

我想使用 JSNI 在 GWT 中使用phonegap 音频 api。我不知道如何在 JSNI 中编写方法。

不知道是否有人知道任何教程。它们的 javascript 方法真的非常简单。

http://docs.phonegap.com/phonegap_media_media.md.html

I am wanting to use the phonegap audio api in GWT using JSNI.I cannot figure out how to code the methods in JSNI.

Wondering if anyone know of any tutorials.They javascript methods are really pretty simple.

http://docs.phonegap.com/phonegap_media_media.md.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以可爱出名 2024-10-14 09:27:40

基本上听起来就像这样:

public final class Media extends JavaScriptObject {
  protected Media() {}

  public static native final Media newInstance(String src, Command command) /*-{
    var callback = function() { command.execute(); };
    return new Media(src, callback);
  }-*/;

  public native final void getCurrentPosition(AsyncCallback<String> command) /*-{
    var callback = function(position) { command.onSuccess('' + position); };
    this.getCurrentPosition(callback);
  }-*/;
  public native final void play() /*-{
    this.play();
  }-*/;
  //... more methods here
}

用法:

Media m = Media.newInstance("http://www.example.com/src.mp3", new Command() {
  @Override
  public void execute() {
    // Code executed after Media is created.
  }
});
m.getCurrentPosition(new AsyncCallback<String>() {
  @Override
  public void onSuccess(String position) {
    Window.alert(position);
  }
});
m.play();

这是一个粗略的草图,如果您更多地了解传递给回调的类型是什么,您可以做更好的事情,例如将其设为 int或其他 JS 覆盖类型。

API 有点奇怪,因为一切显然都是异步的,但这就是生活。

一旦掌握了编写 GWT JSNI 绑定的窍门,一切就变得非常简单了。

如果您最终在这条路上走得更远,那么如果您开源 GWT 包装器库,以便其他 GWT 开发人员可以编写一些 iPhone/Android 应用程序,那就太棒了。

Basically it sounds like it would be something like this:

public final class Media extends JavaScriptObject {
  protected Media() {}

  public static native final Media newInstance(String src, Command command) /*-{
    var callback = function() { command.execute(); };
    return new Media(src, callback);
  }-*/;

  public native final void getCurrentPosition(AsyncCallback<String> command) /*-{
    var callback = function(position) { command.onSuccess('' + position); };
    this.getCurrentPosition(callback);
  }-*/;
  public native final void play() /*-{
    this.play();
  }-*/;
  //... more methods here
}

Usage:

Media m = Media.newInstance("http://www.example.com/src.mp3", new Command() {
  @Override
  public void execute() {
    // Code executed after Media is created.
  }
});
m.getCurrentPosition(new AsyncCallback<String>() {
  @Override
  public void onSuccess(String position) {
    Window.alert(position);
  }
});
m.play();

That's a rough sketch, if you know more about what the type being passed to the callback is you can do nicer things like have it be an int or another JS Overlay Type.

The API is kind of weird because everything is apparently asynchronous, but that's life.

Once you've gotten the hang of writing GWT JSNI bindings it's pretty straightforward.

If you end up getting further down this road, it would be awesome if you open-sourced your GWT wrapper library so other GWT developers could write some iPhone/Android apps.

甜嗑 2024-10-14 09:27:40

我真的只需要播放方法。我猜我不太了解如何正确执行此操作。该代码对我来说看起来很陌生:-)

仍然无法接受你的答案。该网站无法识别我,这很奇怪。

尝试在 onModuleLoad 中使用媒体时出现以下错误

构造函数 TESTPHONEGAP.Media(String, new Command(){}) 未定义

Media m = new Media("test.mp3", new Command() {
           @Override
           public void execute() {

           }
         });
       m.play()

在与我的主 onModuleLoad 相同的文件中使用您的类作为“内部类”

I just need the play method really.I am not quite as knowledgeable to do this correctly I guess.That code looks really foreign to me :-)

Still cannot accept your answer.The site does not recognize me it is strange.

I get the following error when trying to use the media in my onModuleLoad

The constructor TESTPHONEGAP.Media(String, new Command(){}) is undefined

Media m = new Media("test.mp3", new Command() {
           @Override
           public void execute() {

           }
         });
       m.play()

Using your class as an "inner class" in same file as my main onModuleLoad

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文