大约一周之后...我认为是时候问问SO社区了:)

现在,我已经有一个正在运行的(正在执行中的)插件。

扩展CordovaPlugin的Java文件:

Intent objIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), MY_SERVICE.class);

//pass the url to the service
objIntent.putExtra("mediaUrl", url);

//Start the service
cordovaObj.getActivity().getApplicationContext().startService(objIntent);

然后,在服务的onCreate方法中,我将androids的本机MediaPlayer类设置为空,并在服务的onStartCommand()中启动播放器。我也有停止方法。一旦它开始工作,我想尝试和Vitamio交换andriod mediaplayer类。

我做了以下https://github.com/yixia/VitamioBundle/wiki/Getting-Started

他们有四个简单的指令,第四个是。
“现在您可以使用与Android Media API相同的Vitamio Media API” ... ?? .. um..no

将所有文件都放在正确的位置,并且 list 中有正确的 Activity 和服务声明,但是在编译后我的应用程序在劳赫崩溃了。

步骤3是我无法致电的问题
if (!io.vov.vitamio.LibsChecker.checkVitamioLibs(this))

在我的服务类中的onCreate方法中,我得到并出错。我尝试将其放置在MainActivity的onCreate中,但在启动时崩溃
    LAUNCH SUCCESS
E/AndroidRuntime(23282): java.lang.RuntimeException: Unable to start activity ComponentInfo{biz.urassociation.app/biz.urassociation.app.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaInterfaceImpl.setActivityResultRequestCode(int)' on a null object reference
E/AndroidRuntime(23282): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaInterfaceImpl.setActivityResultRequestCode(int)' on a null object reference
E/AndroidRuntime(23282):    at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:331)

主要问题是,如果在 Activity 中使用此功能,我是否会被迫使用接口(interface)?

我只想在后台流式传输音频,而用户可以浏览我的应用程序并使用BroadcastReceiver意图从插件到服务或返回位置或播放器状态停止,暂停,seekTo ... etc。

有人可以帮忙吗?

基本上我想使用没有寡妇,小部件,播放器界面等的vitamio,我将通过cordova插件进行控制。我如何以这种方式使用vitamio ...任何帮助都会很棒。

Vitamio-Cor dova-Plugin可以很好地工作,并且可以播放使用本地MediaPlayer通常无法正常工作的HLS流...但是我只想播放音频...我注释了所有接口(interface)代码,但仍然看不见直到我点击“后退”按钮为止,该窗 Eloquent 阻止我使用我的应用程序。我不想只使用ndroid:theme =“@ android:style / Theme.NoDisplay”并修改播放器应作为服务运行的插件……这对于音频播放器来说都是正确的方法。再次感谢您的帮助,我已经尽我所能尽力了,但是最后我寻求您的帮助。

最佳答案

哇。不敢相信我在日志中错过了这个。

我没有声明vitamio的初始化方法使用的必要的字符串资源:/ ..位于res / values / strings.xml中……一切正常工作。

简而言之,如果您使用的是Cordova,请执行此操作。

  • 将vitamio初始化添加到您的MainActivity应该如下所示
    import io.vov.vitamio.LibsChecker; //don't forget to import this!
      public class MainActivity extends CordovaActivity
      {
          @Override
          public void onCreate(Bundle savedInstanceState)
          {
              super.onCreate(savedInstanceState);
              if (!LibsChecker.checkVitamioLibs(this))
              return;
                  // Set by <content src="index.html" /> in config.xml
                  loadUrl(launchUrl);
           }
      }
    
  • 确保您的plugin.xml中具有所有字符串引用,如下所示
        <config-file target="res/values/strings.xml" parent="/resources">
        <string name="vitamio_library_app_name">VitamioLibrary</string>
        <string name="vitamio_init_decoders">Initializing decoders…</string>
        <string name="permission_group_tools_label">Vitamio tools</string>
        <string name="permission_group_tools_description">Access Vitamio package and resources.</string>
        <string name="permission_receive_messages_label">Receive Vitamio messages</string>
        <string name="permission_receive_messages_description">Receive all broadcasts from Vitamio service.</string>
        <string name="permission_write_providers_label">Write Vitamio providers</string>
        <string name="permission_write_providers_description">Delete, update or create new items in Vitamio providers.</string>
        <string name="VideoView_error_title">Cannot play video</string>
        <string name="VideoView_error_text_invalid_progressive_playback">Sorry, this video is not valid for streaming to this device.</string>
        <string name="VideoView_error_text_unknown">Sorry, this video cannot be played.</string>
        <string name="VideoView_error_button">OK</string>
        <string name="mediacontroller_play_pause">Play/Pause</string>
    </config-file>
    
  • 在您的android list 中...
    <activity android:name="io.vov.vitamio.activity.InitActivity" android:configChanges="orientation|screenSize|smallestScreenSize|keyboard|keyboardHidden" android:launchMode="singleTop" android:theme="@android:style/Theme.NoTitleBar" android:windowSoftInputMode="stateAlwaysHidden"/>
    
    <activity android:configChanges="orientation|keyboardHidden|navigation" android:launchMode="singleTop" android:name="io.vov.vitamio.activity.InitActivity" android:theme="@android:style/Theme.NoDisplay" android:windowSoftInputMode="stateAlwaysHidden" />
    

  • 现在,您应该可以正常使用vitamio Media类了。
    在某个时候,我将为此编写一个教程,以免人们发疯:}

    顺便说一句,显然要确保您也安装了vitamio库,您可以查看https://github.com/nchutchind/Vitamio-Cordova-Plugin看看他是如何做到的……那就是我所做的。伟大的插件顺便说一句。

    10-04 22:49
    查看更多