为什么 Ionic 1 Media Plugin Error {"code" : 1} 播放 N 次后? (android)
Why Ionic 1 Media Plugin Error {"code" : 1} after playing N times? (android)
我知道这很奇怪,但这是我的观察:
我使用 Ionic 1 中的媒体插件播放了一些音乐:
//Method 1: just plugin
mediaRes = new Media(myMusicPath, onMediaSuccess, onMediaError, onMediaStatus);
//Method 2: ngCordova
mediaRes = $cordovaMedia.newMedia(myMusicPath)
mediaRes.play().then(onMediaSuccess, onMediaError, onMediaStatus);
从其他帖子读到的,路径很关键:
"/android_asset/www/music/mymusic.mp3"
基本上路径名已经印在我的HTML上了,不会错的
前N次正常。然后,在第 (N + 1) 次,它失败并出现错误 {"code":1}.
为什么会这样?在重新初始化变量之前,我是否需要以某种方式清除缓存或其他东西?目前我每次 运行 都会重新初始化变量。
编辑:
似乎只要执行'play()'
就可以无限播放,而无需再次重新初始化同一个变量。会继续观察...
release()
Releases the underlying operating system’s audio resources. This is
particularly important for Android, since there are a finite amount of
OpenCore instances for media playback. Applications should call the
release function for any Media resource that is no longer needed.
显然,release
函数是必需的。这解决了问题。
我知道这很奇怪,但这是我的观察:
我使用 Ionic 1 中的媒体插件播放了一些音乐:
//Method 1: just plugin
mediaRes = new Media(myMusicPath, onMediaSuccess, onMediaError, onMediaStatus);
//Method 2: ngCordova
mediaRes = $cordovaMedia.newMedia(myMusicPath)
mediaRes.play().then(onMediaSuccess, onMediaError, onMediaStatus);
从其他帖子读到的,路径很关键:
"/android_asset/www/music/mymusic.mp3"
基本上路径名已经印在我的HTML上了,不会错的
前N次正常。然后,在第 (N + 1) 次,它失败并出现错误 {"code":1}.
为什么会这样?在重新初始化变量之前,我是否需要以某种方式清除缓存或其他东西?目前我每次 运行 都会重新初始化变量。
编辑:
似乎只要执行'play()'
就可以无限播放,而无需再次重新初始化同一个变量。会继续观察...
release()
Releases the underlying operating system’s audio resources. This is particularly important for Android, since there are a finite amount of OpenCore instances for media playback. Applications should call the release function for any Media resource that is no longer needed.
显然,release
函数是必需的。这解决了问题。