Giter VIP home page Giter VIP logo

cordova-plugin-media's Issues

iOS: Crash in [CDVSound startPlayingAudio:] with version 3.0.1 and 5.0.2

Hi there,

I am receiving crashreports from my users (via iTunesConnect) related to [CDVSound startPlayingAudio:]

It is very hard to reproduce this issue and it does not occur very often. May be releated to specific usage, devices or threading.

I wonder if this issue is already known and potentially fixed. I'll upgrade to version 5.0.1 and let you know if it still occurs.

Full logfile
cdv.crash.txt

Interesting log sections:

Thread 32 Crashed:
0   AVFAudio                      	0x000000018a25880c AVAudioPlayerCpp::AQOutputCallbackCore(OpaqueAudioQueue*, AudioQueueBuffer*) + 180 (AVAudioPlayerCpp.mm:1250)
1   AVFAudio                      	0x000000018a257e84 AVAudioPlayerCpp::prepareToPlayQueue() + 224 (AVAudioPlayerCpp.mm:883)
2   AVFAudio                      	0x000000018a257e84 AVAudioPlayerCpp::prepareToPlayQueue() + 224 (AVAudioPlayerCpp.mm:883)
3   AVFAudio                      	0x000000018a257fe0 AVAudioPlayerCpp::playQueue(AudioTimeStamp const*) + 112 (AVAudioPlayerCpp.mm:956)
4   AVFAudio                      	0x000000018a256760 AVAudioPlayerCpp::play() + 80 (AVAudioPlayerCpp.mm:667)
5   AVFAudio                      	0x000000018a218414 -[AVAudioPlayer play] + 52 (AVAudioPlayer.mm:455)
6   MYAPP                 	        0x00000001041a16d4 __30-[CDVSound startPlayingAudio:]_block_invoke + 1648 (CDVSound.m:402)
7   libdispatch.dylib             	0x00000001841b4aa0 _dispatch_call_block_and_release + 24 (init.c:994)
8   libdispatch.dylib             	0x00000001841b4a60 _dispatch_client_callout + 16 (object.m:507)
9   libdispatch.dylib             	0x00000001841bbb84 _dispatch_queue_override_invoke$VARIANT$mp + 716 (inline_internal.h:2500)
10  libdispatch.dylib             	0x00000001841c1cac _dispatch_root_queue_drain + 588 (inline_internal.h:2539)
11  libdispatch.dylib             	0x00000001841c19fc _dispatch_worker_thread3 + 120 (queue.c:6092)
12  libsystem_pthread.dylib       	0x00000001844e7fac _pthread_wqthread + 1176 (pthread.c:2297)
13  libsystem_pthread.dylib       	0x00000001844e7b08 start_wqthread + 4

iOS - Playback failure from device filesystem

I'm having issues playing audio files from a local filesystem on iOS. Please see below for relevant debugging info...

XCODE Output :

2018-09-12 09:16:22.875388+0100 DK EFE[11346:64268] Will attempt to use file resource 'file:///Users/myname/Library/Developer/CoreSimulator/Devices/F7857F73-B645-42C2-8F2C-541E635F9163/data/Containers/Data/Application/D18F7ECE-1809-450B-A644-52E98CD49409/Library/NoCloud/audio/b1/c/3/b1_c_3_2_uk.mp3'

2018-09-12 09:16:22.875580+0100 DK EFE[11346:64268] Unknown resource 'file:///Users/myname/Library/Developer/CoreSimulator/Devices/F7857F73-B645-42C2-8F2C-541E635F9163/data/Containers/Data/Application/D18F7ECE-1809-450B-A644-52E98CD49409/Library/NoCloud/audio/b1/c/3/b1_c_3_2_uk.mp3'

JS Console Output :

{
  code: 1,
  message: "Cannot use audio file from resource 'file:///Users...'
}

Playback is successful when streaming via Cloudfront CDN but fails when attempting to load locally. The same application is running without any issues on Android.

The debugging output above is fro xcode but experiencing the same issues running application via TestFlight.

Any ideas?

Record from Bluehooth / Headset / Headphones?

Bug Report

Problem

When using this plugin with a device connected to a bluetooth headset, the play() method outputs to the headset (as expected), not the device's speaker, but the .startRecord()/.stopRecord sequence does not capture sounds being played through the headsets. (the use case: to capture a snippet of sound being played back).

Is this expected? I don't know if this is a bug or a feature :) but there appears to be no configuration option to record from the bluetooth channel.

What is expected to happen?

The recording should capture the sound (and input if it exists) from the Bluetooth headset.

What does actually happen?

The recording only captures sound from the device's speaker.

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • [ x] I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

alternative to file/url

Feature Request

We are using this to stream songs from a server, but would like to cache them as well. It's hard to customise since the Media component directly takes a path or a url. Have you thought if accepting a kind of resourceObject as an interface that can be customised instead of a path as string?

Motivation Behind Feature

Allows to customise how data is processed, ea. streamed and saved to file at the same time. Additionally allows to customise the outgoing requests with headers.

Feature Description

Alternatives or Workarounds

Alternatives so far have been looking into trying to run a local Cordova WebServer to proxy these requests.

getDuration() returns -1, then 0 on some remote MP3 files

I'm on iOS (using Ionic) and start playing remote files (hosted on AWS). I set a timer to get the duration. If getDuration() returns -1, I call the timer again. On most of the files, the audio starts playing and eventually, I get the correct duration of the MP3 .

However, on some files, it will eventually return 0 for the duration and the audio never plays. If I download that same file first and then play it, there is no problem playing or getting the duration.

All files are 64bit encoded MP3.

What would cause a remote file not to play and return 0 for getDuration()?

how to record video

how to record video using cordova-plugin-media
I dont want to use cordova-plugin-media-capture
Also i want to record video and audio within app not from default device recorders...

onSuccess is not working

window.$c_media = new Media(musicSrc, function () {alert('success!!!')}, mediaError)

the onSuccess is not called

getDuration returns a big number like 316000 and I can't kill the media file anywhere I still bloqued.

Hi everybody,

I'm working in Ionic 3 Project and All My current Project is based on this plugin, I get an issue when I try to get the duration for more then 30 local files in Android 5.01 and Android 5.1 ( I have tested only in those 2 devices )

So for test purpose I duplicate the same src local file in 30 tracks, and I try to get their duration all, sometimes it works fine but for more then 30 tracks the last tracks, getDuration() return a big number as 316520, and the Media File still bloqued at this situation:

I'm asking how to free or kill the Media file when it's bloqued in this situation Or is there a Direct Solution for this problem:

My Function Code:

getDurationAndSetToPlay(index,url){
    this.myTracks[index] = this.media.create(url);
    this.myTracks[index].play();
    this.myTracks[index].setVolume(0.0);
    let self = this;

    this.tracks[index].get_duration_interval = setInterval(()=> {
        self.tracks[index].duration = ~~(self.myTracks[index].getDuration());

          if(self.tracks[index].duration > 0) {
            self.stopPlayRecording(index);
            self.myTracks[index].setVolume(1.0);
            self.myTracks[index].stop();
            self.setRecordingToPlay(index);
            clearInterval(self.tracks[index].get_duration_interval);

          }
    }, 500);
}

I'm using a for loop to call this function to get all tracks duration simutaniously:

for (let index in urls){
    this.getDurationAndSetToPlay(index,urls[index]);

My Local URL is like:
let urlLocal = this.file.externalRootDirectory+"MyProject/Folder1/Folder2/audioFile.mp3";

The Last Tracks after the 30 first Tracks are All bloqued at status code = 2 but doesn't play really and their duration still big number 316578 ..

Please Help Me I have to provide an App which supports 100 tracks (local files)

Start record return error code 1 on Android

Hello everyone,
I use the version 5.0.2.
When i start a record like code below, the plugin returns an error : code 1, only on android.
Could you help me please?

My code is :

var fileName = 'test.3gp';
var filePathAudio = this.file.dataDirectory.replace(/file:\/\//g, '') + fileName;
var fileAudio1 = this.media.create(filePathAudio);

fileAudio1.onStatusUpdate.subscribe((status) => {
	alert(status);
	if(status==this.media.MEDIA_RUNNING) {
		alert("it s running");
	}
});
				
fileAudio1.onError.subscribe((error) => {
	this.safetynApi.displayAlert('fileAudio1 :'+ error);
	this.safetynApi.displayAlert(error);
});

fileAudio1.startRecord();

Thanks in advance.

Best regards

MediaError.MEDIA_ERR_ABORTED = 1 on Android?

Anyone knows what does it mean this error? iOS is working fine but Android is not playing the audio and showing this error.

I'm using Cordova 8, Cordova Android 7.1 and Plugin 5.0.2
I've tried M4A and MP3 files.

onSuccess call back of media.play breaks angular 4 change detection

Hi Team,

i am using angular 4 with cordova-media-plugin, after playing an audio, the success call back not performing two way data binding,

Tried changeDetRef, ApplicationRef and ngzone, for all of these error is throughing "undefined is not an object (evaluating '_this.changeDetRef.detectChanges')"

Tried to invoke another method but no luck,

Tried for observable and subscribers no luck.

please can any one help me on this

Thanks,
Praveen

iOS: seekTo crashes if the URL provided is served by WKWebView

I use this plugin to play remote urls and at the same time to cache those file for following plays.
To achieve file caching both file and file-transfer are used. In adding I also use ionic-webview WKWebview engine which has an WebServer that will serve cached files.

The issue that I have is related with seekTo function which works when Media is created from a remote url.

For example when using a remote url:
var track = new Media("https://remote.url/never_gonna_give_you_up.mp3", onTrackEnd, onTrackError, onTrackStatus);
I'm able to play actual song and using track.seekTo(5000); always works.

However when track is created from a URL that is served by WebServer (localhost), e.g.:
var track = new Media("http://localhost:8080/_file_/var/mobile/Containers/Data/Application/99ADB8B6-6915-4802-BBC5-0EDE9127A5C4/Library/files/never_gonna_give_you_up.mp3", onTrackEnd, onTrackError, onTrackStatus);
I'm able to pause and play the track however as soon I try to seekTo the app crashes.

After looking through the source code I couldn't find the reason to happen only for locally served files however there was an similar issue CB-10535 and a PR #82 which showcased similar issue that occurred however on remote files.

Could it be that WebServer itself doesn't respond correctly back to AVPlayer, hitting a wrongful state?

How to release() properly

Many thanks for the wonderful plugin. I am using it in many ionic 3 projects and it works great! However, I am facing some resource release issue and I don't know how to address.

I have a list of song

song1
song2
song3

When user tap song1, I play song1.mp3. If user tap song2 before song1 finishes, I’d like to stop song 1 and start playing song2. My question is how to do it without memory leaking.

I tried:

play(song) {

const file: MediaObject = this.media.create('song');

// to listen to plugin events:

file.onStatusUpdate.subscribe(status => console.log(status)); // fires when file status changes

file.onSuccess.subscribe(() => console.log('Action is successful'));

file.onError.subscribe(error => console.log('Error!', error));

// play the file
file.play();

}

I don’t know how to stop and release the previous song. Can anyone help?

Response time and play mp3 samples

Hi Guys, help us please.

I have two problems when I use this plugin:

  1. I can not play one and the same mp3 parallel and at the same time
  2. I can not do mp3 preload to reduce the response time when creating an instance

Maybe you have any ideas on this?

Android: Crash and asserts because of missing buffer (buffer == NULL)

Hi there,

I noticed asserts when playing audio: buffer == NULL

As long as I play local files only, no crashes occur. But if I stream audio using an unstable network connection (cellular data), the App starts crashing from time to time.

Update vom 3.0.1 to 5.0.2 did not help.

The asserts can be reproduced - example with android emulator:

I20180824-13:03:10.106(2)? 08-24 13:03:10.037  4801  4807 F AudioTrackShared: Assertion failed: buffer == NULL || buffer->mFrameCount == 0
I20180824-13:03:10.112(2)? 08-24 13:03:10.037  4801  4807 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 4807 (FastMixer)
I20180824-13:03:10.113(2)? 08-24 13:03:10.039  1359  1359 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I20180824-13:03:10.113(2)? 08-24 13:03:10.040  1359  1359 F DEBUG   : Build fingerprint: 'Android/sdk_google_phone_x86/generic_x86:6.0/MASTER/4729342:userdebug/test-keys'
I20180824-13:03:10.113(2)? 08-24 13:03:10.040  1359  1359 F DEBUG   : Revision: '0'
I20180824-13:03:10.114(2)? 08-24 13:03:10.040  1359  1359 F DEBUG   : ABI: 'x86'
I20180824-13:03:10.114(2)? 08-24 13:03:10.040  1359  1359 F DEBUG   : pid: 4801, tid: 4807, name: FastMixer  >>> /system/bin/mediaserver <<<
I20180824-13:03:10.114(2)? 08-24 13:03:10.040  1359  1359 F DEBUG   : signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
I20180824-13:03:10.115(2)? 08-24 13:03:10.046  1359  1359 F DEBUG   : Abort message: 'Assertion failed: buffer == NULL || buffer->mFrameCount == 0'
I20180824-13:03:10.117(2)? 08-24 13:03:10.046  1359  1359 F DEBUG   :     eax 00000000  ebx 000012c1  ecx 000012c7  edx 00000006
I20180824-13:03:10.120(2)? 08-24 13:03:10.046  1359  1359 F DEBUG   :     esi b41ff980  edi 00000000
I20180824-13:03:10.121(2)? 08-24 13:03:10.046  1359  1359 F DEBUG   :     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b
I20180824-13:03:10.121(2)? 08-24 13:03:10.046  1359  1359 F DEBUG   :     eip b6f4ba56  ebp 000012c7  esp b41fee80  flags 00200202
I20180824-13:03:10.121(2)? 08-24 13:03:10.050  1359  1359 F DEBUG   : 
I20180824-13:03:10.122(2)? 08-24 13:03:10.050  1359  1359 F DEBUG   : backtrace:
I20180824-13:03:10.122(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #00 pc 00083a56  /system/lib/libc.so (tgkill+22)
I20180824-13:03:10.122(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #01 pc 00081608  /system/lib/libc.so (pthread_kill+70)
I20180824-13:03:10.122(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #02 pc 00027205  /system/lib/libc.so (raise+36)
I20180824-13:03:10.123(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #03 pc 000209e4  /system/lib/libc.so (abort+80)
I20180824-13:03:10.123(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #04 pc 0000cbc3  /system/lib/libcutils.so (__android_log_assert+128)
I20180824-13:03:10.123(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #05 pc 0008353d  /system/lib/libmedia.so (android::ServerProxy::obtainBuffer(android::Proxy::Buffer*, bool)+669)
I20180824-13:03:10.124(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #06 pc 00053af7  /system/lib/libaudioflinger.so
I20180824-13:03:10.124(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #07 pc 00066155  /system/lib/libaudioflinger.so
I20180824-13:03:10.124(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #08 pc 0002630a  /system/lib/libaudioflinger.so
I20180824-13:03:10.125(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #09 pc 00026d42  /system/lib/libaudioflinger.so
I20180824-13:03:10.125(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #10 pc 00025e93  /system/lib/libaudioflinger.so
I20180824-13:03:10.126(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #11 pc 0006c19a  /system/lib/libaudioflinger.so
I20180824-13:03:10.126(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #12 pc 0006d88f  /system/lib/libaudioflinger.so
I20180824-13:03:10.126(2)? 08-24 13:03:10.051  1359  1359 F DEBUG   :     #13 pc 00014aac  /system/lib/libutils.so (android::Thread::_threadLoop(void*)+418)
I20180824-13:03:10.127(2)? 08-24 13:03:10.052  1359  1359 F DEBUG   :     #14 pc 000141cf  /system/lib/libutils.so (thread_data_t::trampoline(thread_data_t const*)+122)
I20180824-13:03:10.127(2)? 08-24 13:03:10.052  1359  1359 F DEBUG   :     #15 pc 00080ab3  /system/lib/libc.so (__pthread_start(void*)+56)
I20180824-13:03:10.127(2)? 08-24 13:03:10.052  1359  1359 F DEBUG   :     #16 pc 00021952  /system/lib/libc.so (__start_thread+25)
I20180824-13:03:10.128(2)? 08-24 13:03:10.052  1359  1359 F DEBUG   :     #17 pc 000170b6  /system/lib/libc.so (__bionic_clone+70)
I20180824-13:03:10.231(2)? 08-24 13:03:10.162  1359  1359 F DEBUG   : 
I20180824-13:03:10.232(2)? 08-24 13:03:10.162  1359  1359 F DEBUG   : Tombstone written to: /data/tombstones/tombstone_05
I20180824-13:03:14.317(2)? 08-24 13:03:14.245  4119  4119 I chromium: [INFO:CONSOLE(1377)] "Media Error Code 100", source: http://localhost:12128/app/app.js?hash=727c3461de63aa79ea38d941e57c1c7c13d6e8fc (1377)
I20180824-13:03:14.322(2)? 08-24 13:03:14.251  4119  4119 I chromium: [INFO:CONSOLE(1378)] "cdvfile://localhost/persistent/z9RBuHyxn2NPgbNKi.m4a", source: http://localhost:12128/app/app.js?hash=727c3461de63aa79ea38d941e57c1c7c13d6e8fc (1378)
I20180824-13:03:14.382(2)? 08-24 13:03:14.310  4824  4830 F AudioTrackShared: Assertion failed: buffer == NULL || buffer->mFrameCount == 0
I20180824-13:03:14.383(2)? 08-24 13:03:14.310  4824  4830 F libc    : Fatal signal 6 (SIGABRT), code -6 in tid 4830 (FastMixer)
I20180824-13:03:14.384(2)? 08-24 13:03:14.314  1359  1359 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

startRecord function of cordova media has two parameters(sampleRate: number, bitRate: number)!

I have no idea why I need to specify two parameters to the function of startRecord while using cordova-plugin-media. Here is the source code I used in index.d.ts.
startRecord(sampleRate: number, bitRate: number): void;

My code is below:
if (!this.recordMedia) { this.recordMedia = new Media().create(path) this.recordMedia.onError.subscribe(code => this.handleMediaError(code)) this.recordMedia.onStatusUpdate.subscribe(status => this.handleMediaStatus(status)) this.recordMedia.onSuccess.subscribe(() => this.completeRecord()) this.recordMedia.startRecord() }

I got error when I use this.recordMedia.startRecord(), my IDE tells my I need to add two parameters.

Here is my vscode tip:
(method) MediaObject.startRecord(sampleRate: number, bitRate: number): void
Starts recording an audio file.

Expected 2 arguments, but got 0.ts(2554)
index.d.ts(77, 17): An argument for 'sampleRate' was not provided.

However, startRecord() don't have any parameters, I have drawn this conclusion after I searched so many documents. For Example:
Quick Example https://cordova.apache.org/docs/en/2.8.0/cordova/media/media.startRecord.html
function recordAudio() { var src = "myrecording.mp3"; var mediaRec = new Media(src, // success callback function() { console.log("recordAudio():Audio Success"); }, function(err) { console.log("recordAudio():Audio Error: "+ err.code); }); mediaRec.startRecord(); }


my cordova-plugin-media version: 5.0.2


Ionic: ionic (Ionic CLI) : 4.12.0 (C:\Users\lychee\AppData\Roaming\npm\node_modules\ionic) Ionic Framework : ionic-angular 3.9.3 @ionic/app-scripts : 3.2.1 Cordova: cordova (Cordova CLI) : 9.0.0 ([email protected]) Cordova Platforms : android 8.0.0 Cordova Plugins : not available System: Android SDK Tools : 26.1.1 (D:\Program Files (x86)\Android\Sdk) NodeJS : v10.15.1 (C:\Program Files\nodejs\node.exe) npm : 6.4.1 OS : Windows 10

When I recorded, I had the following error:FAILED renaming xx to xx,Couldn't open xx java.io.FileNotFoundException: No content provider

Here is my code snippet:

if (this.platform.is('ios')) {
      this.file.createFile(this.file.cacheDirectory, this.voiceMediaObj.fileName, true).then(entry => {
        this.voiceMediaObj.vocieMediaFile = this.media.create(entry.toURL());
      });
    } else if (this.platform.is('android')) {
      this.voiceMediaObj.vocieMediaFile = this.media.create(this.voiceMediaObj.vocieMediaFilePath);
    }
    this.voiceMediaObj.vocieMediaFile.startRecord();

When the stopRecord () method is called, the following error occurs:

09-09 22:57:35.848 16978-17106/net.ws315.dalai D/AudioPlayer: renaming /storage/emulated/0/tmprecording-1536505053393.3gp to /data/user/0/net.ws315.dalai/cache/1536505053071.aac

09-09 22:57:35.849 16978-17106/net.ws315.dalai E/AudioPlayer: FAILED renaming /storage/emulated/0/tmprecording-1536505053393.3gp to /data/user/0/net.ws315.dalai/cache/1536505053071.aacFAILED renaming /storage/emulated/0/tmprecording-1536505053393.3gp to /data/user/0/net.ws315.dalai/cache/1536505053071.aac

09-09 22:57:35.849 16978-17106/net.ws315.dalai W/PluginManager: THREAD WARNING: exec() call to Media.stopRecordingAudio blocked the main thread for 114ms. Plugin should use CordovaInterface.getThreadPool().

09-09 22:57:35.910 16978-17108/net.ws315.dalai W/MediaPlayer: Couldn't open /data/user/0/net.ws315.dalai/cache/1536505053071.aac: java.io.FileNotFoundException: No content provider: /data/user/0/net.ws315.dalai/cache/1536505053071.aac

09-09 22:57:35.911 16978-17108/net.ws315.dalai I/MediaPlayerNative: setDataSource(114, 0, 576460752303423487)

09-09 22:57:35.913 16978-17108/net.ws315.dalai E/MediaPlayerNative: Unable to create media player

after using the plugin youtube cannot play videos on IOS 11 and 12

My App uses Ionic-native-media to record audio then play back, after this happens, youtube cannot play videos inside in-app-browser

What is expected to happen?

Plugin should not affect youtube video playing

What does actually happen?

After plugin is called for audio recording, youtube cannot play video inside in-app-browser

Information

Ios 11 or 12
Ionic 2 , Ionic-native 4, ionic native media plugin.
record audio using media plugin
play back the audio
open a youtube page inside in-app-browser
video does not play

Command or Code

startrecord(){
try{
  this.filename = this.filename.replace(".wav",Number(new Date()).toString()+".wav");
  this.recordStatus =1;
  //IOS
  this.file.createFile(this.file.tempDirectory, this.filename, true).then(() => {
    this.file.checkFile(this.file.tempDirectory,this.filename).then(()=>{
    this.mfile  = this.media.create(this.file.tempDirectory.replace(/^file:\/\//, '') + this.filename);
    this.mfile.startRecord();
  },()=>{alert('File does not exist' + this.dir+this.filename);
  
});
  });

}catch(e){alert('error2:'+e);}
}

stoprecord(){
try{
  //
  this.mfile.stopRecord();
  this.mfile.release();
  this.recordStatus =2 ;
   this.file.checkFile(this.file.tempDirectory,this.filename).then(()=>{ //alert('exists');
    },()=>{
    this.file.resolveLocalFilesystemUrl(this.file.tempDirectory+this.filename)
    .then(r => {
      try{this.playback(r)}catch(e){console.log(JSON.stringify(e));}}
      )
    .catch(e => alert('error1:'+JSON.stringify(e)));
  
}catch(e){alert('error:'+ JSON.stringify(e));} 
}

playback(r){
      this.play(r.nativeURL.replace(/^file:\/\//, ''));
    }


play(url)
{
  
  this.myaudio = new Audio(url);
  var readyStateInterval = null;
  if(this.myaudio !=null && this.myaudio.paused)
      {
        this.myaudio.play();
        
        return;}
  readyStateInterval = setInterval(function(this){
      if (this.readyState <= 2) {
      this.playstatus=this.readyState;
      }
   },1000);
   
openlink(){
        const browser = this.iab.create('https://www.youtube.com/watch?v=C0DPdy98e4c','_blank');
      
  }
}

Environment, Platform, Device

Ios 11 or 12
Ionic:

ionic (Ionic CLI) : 4.5.0 (C:\Users\admin\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.1.5

Cordova:

cordova (Cordova CLI) : not installed
Cordova Platforms : android 6.3.0, browser 5.0.4, ios 4.5.4
Cordova Plugins : cordova-plugin-ionic-webview 1.1.1, (and 16 other plugins)

System:

NodeJS : v10.13.0 (C:\Program Files\nodejs\node.exe)
npm : 6.5.0
OS : Windows 10

Callback Status MEDIA_STARTING

Please add callback status MEDIA_STARTING to iOS
cordova-plugin-media/src/ios/CDVSound.m: 355

from

if (!bError) {
            //self.currMediaId = audioFile.player.mediaId;
            self.currMediaId = mediaId; ...

to

if (!bError) {

            [self onStatus:MEDIA_STATE mediaId:mediaId param:@(MEDIA_STARTING)];
            
            //self.currMediaId = audioFile.player.mediaId;
            self.currMediaId = mediaId; ...``

Saving recording file not working on Samsung devices

Hello,

We use this plugin to record audio fragments and save them in our app. On some phones we are unfortunately unable to save the recorded audio fragment in our app. The issue is reproducable on all Samsung devices we tried, ranging from Android 4.4 to 7.0.

What happens: We initiate recording and finish creating an audio fragment. Then, we click a paperclip icon in the Samsung recording app, but the audio fragment is never taken back into our app. Why does this happen? Is there a way to properly troubleshoot this?

It works fine on Huawei P10 (Android 8.0.0) and Sony Xperia Z3 (Android 6.0)

What worries me is that every brand of devices seem to have their own recording app, with different implementations. Is there a way to standardize the recording app or create a buildin recording system, without requiring the users to install another app? If so, I'd love to hear about that.

PS: I saw there's also a cordova-plugin-media-capture. What's the difference between this one and that one?

Many thanks in advance!

Here's the code that is responsible for our recordings:

.controller('RecordingCtrl', function ($scope, $ionicPlatform, $cordovaFile, $timeout, database) {
    var recordingDirectory;
    var rootDirectory;
    $scope.entries = [];
    $scope.disablePlaying = false;
    $scope.renaming = false;
    $scope.soundplaying = false;
    $scope.alertNameChange = false;

    $scope.$on('$ionicView.enter', function () {
        loadRecordings();
    });
    $ionicPlatform.ready(function () {
        var extension = (ionic.Platform.isIOS()) ? '.wav' : '.amr';
        recordingDirectory = "helpy/recordings";

        rootDirectory = cordova.file.applicationStorageDirectory;
        rootDirectory += (ionic.Platform.isIOS()) ? 'Library/' : 'files/';
        $scope.recordAudio = function () {
            var captureError = function (e) {
                console.dir('captureError', e);
            };
            var captureSuccess = function (mediaFiles) {
                var i, len;
                for (i = 0, len = mediaFiles.length; i < len; i++) {
                    $cordovaFile.checkDir(rootDirectory, recordingDirectory)
                        .then(function () {
                        }, function () {
                            $cordovaFile.createDir(rootDirectory, "helpy", false);
                            $cordovaFile.createDir(rootDirectory, recordingDirectory, false);
                        });

                    var filename = $scope.filename = 'opname_' + Math.floor(Date.now() / 1000);
                    var temp_dir = (ionic.Platform.isIOS()) ? cordova.file.tempDirectory : mediaFiles[i].fullPath.replace(mediaFiles[i].name, '');
                    var extension = mediaFiles[i].name.split('.')[1];

                    console.log('temporary directory: ' + temp_dir);

                    $cordovaFile.moveFile(temp_dir, mediaFiles[i].name, rootDirectory + recordingDirectory, filename + "." + extension)
                        .then(function () {
                            database.add('Recordings', {0: filename, 1: 0}).then(function () {
                            });
                            $scope.entries.push({active: 0, name: filename});
                            $scope.alertNameChange = true;
                        }, function (error) {
                            console.dir(error);
                        });
                }
            };

            navigator.device.capture.captureAudio(captureSuccess, captureError);
        };

Dies under iPhone XHR

Dies on first call to
var newSound = new Media( 'assets/sfx/' + name + '.mp3', sfx_success, sfx_failure );

on iPhone XHR.

NSMicrophoneUsageDescription has not been specified as I don't use the microphone.

Playing multiple files sequentially in background doesn't work in iOS

Hello,

I have an app that plays preview mp3's of a music album, i.e. song1, after that song2, ...

Since there's no playBatch() function in the Media object of this plugin, I did that by playing the next file after the last had finished playing. This works great on Android (even in background).

In iOS when I put the app in background (UIBackgroundModes is set correctly in Xcode), it tries to play the next file but fails with error 4.

Here's the log:

2019-01-12 16:52:59.931116+0100 MyApp[13620:2524776] Unable to play audio: (null)
2019-01-12 16:52:59.952107+0100 MyApp[13620:2524565] Error while playing file:
2019-01-12 16:52:59.952184+0100 MyApp[13620:2524565] {"message":"","code":4}

So it seems that the callback in Media.MEDIA_STOPPED doesn't get the needed data in the background, because this is the place where I start playing the next file. But the remote path of the audio file is correctly passed into the Media object. Maybe this isn't possible in iOS in the background at all? I recently noticed that the app is paused here completely, so background sync of user data doesn't seem to be possible neither.

Is there a way to accomplish what I want? Is there a way to have a playMultiple() or playBatch() function or is there another issue with my files?

Thanks in advance!

Bye

How can we loop ?

How to loop ? We can set numberOfLoops property in the call to .play() but it does nothing. I need perfect looping inside my app ... anybody have a solution?

Tests fail on Safari

2 tests unexpectedly fail when run on a Safari browser on Travis:
https://travis-ci.org/apache/cordova-plugin-media/jobs/547250841

      actual playback
        ✗ media.spec.21 should be able to resume playback after pause
          - media1 = new Media - Error creating Media object. Media file: https://cordova.apache.org/downloads/BlueZedEx.mp3
        ✗ media.spec.22 should be able to seek through file
          - media1 = new Media - Error creating Media object. Media file: https://cordova.apache.org/downloads/BlueZedEx.mp3

Unfortunately this is blocking #227

setRate not working

I haven't tested it with other platforms, but when I use setRate on the browser, it doesn't do affect the sound in any way. Does anyone know a possible fix?

PhoneGap Build Error

Build Date: 2019-01-26 06:10:01 +0000

PLUGIN OUTPUT

Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-vibration" at "3.1.0" for android
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-statusbar" at "2.4.2" for android
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-ignoremuteswitch" at "1.0.1" for android
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-inappbrowser" at "3.0.0" for android
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-x-socialsharing" at "5.4.4" for android
Fetching plugin "es6-promise-plugin@^4.1.0" via npm
Installing "es6-promise-plugin" at "4.2.2" for android
Subproject Path: CordovaLib
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-network-information" at "2.0.1" for android
Fetching plugin "[email protected]" via npm
Installing "cordova-plugin-media" at "5.0.2" for android
Plugin doesn't support this project's cordova-android version. cordova-android: 6.1.2, failed version requirement: >=6.3.0
Skipping 'cordova-plugin-media' for android

Xiaomi phone buffers for a minute before playback starts

Bug Report

Problem

We have testet our app on three devices. One is a Samsung Galaxy S8, one is a Xiaomi Mi Mix 2S, and the last one is a Xiaomi Mi 6. The first two start playback after buffering for 5 seconds on a networks stream, but the Mi 6 buffers for a minute or more before playback starts. It seems to start downloading almost immediately, like the other devices.

What is expected to happen?

Buffering for a few seconds should be enough for a 128kbps stream.

What does actually happen?

Playback should start at roughly the same time on all devices.

Version information

We're using Ionic 4, cordova-plugin-media version 5.0.2.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Playing Audio on Android not working and NO message

I tried the following code:

var mediaPlayneu = new Media("/android_asset/www/sound/beepshort.mp3",

// success callback
function() {
	alert("play3 success");
},
				
// error callback
function(err) {
       alert(JSON.stringify(err)); 
});
						
mediaPlayneu.play();

I get no message and the audio is not playing. What could be the issue?
I tested on Android 5.0, Phonegap cli-6.5.0 and cordova-media-plugin 5.0.2.

Recording voice problem in ionic media plugin

I'm facing recording voice problem in ionic Media Plugin.Actually I need a custom audio recorder in ionic 3 that's why I'm using ionic media plugin.But Once I recorded the audio and then going to play the recorded file, It Plays the audio in Tomcat voice.I don't know why it is happening and most of them are using this plugin and no issues found like this.If anyone familiar with this issue,Please help me.Thanks.

onDestroy and dealloc ambiguity

Currently, it is impossible for client code to interpret the state or event in which the underlying native Media object has been destroyed when the OS is terminating the activity / process. This is a short coming of the plugin, because the success callback is called without any indication that the entire activity or process was stopped abruptly. In other worse, the MEDIA_STOPPED state is too ambiguous . I would like to request a solution to resolve this ambiguity.

There is no way for the plugin to indicate to the client code that the underlying OS is terminating the the process. Please provide a way for client code to discern the difference between OS forcefully stopping the media and the media stopping because it has successfully reached the end of playback.

Convert to eslint

This plugin is still using jshint instead of eslint as all the other Cordova plugins.

media fadeIn and fadeOut effect

Hello

Can this PlugIn reproduce a fadeIn and fadeOut effect for the audio being played?

Whether it is an MP3 or ShoutCast URL ?

If so, which Platforms are supported and do you happen to have a code sample?

Regards

mediaStatus and mediaError callbacks not always firing when Android activity is killed

When killing an app on Android (by swiping the activity to dismiss it), the plugin seems to behave inconsistently. I've noticed one of two things happens:

A: The expected scenario: both the mediaStatus and mediaError get called. This is ideal, since the media status is likely to go from playing (2) or paused (3), to stopped (4) — and being able to execute code based on these events is useful. I agree with @wspresto though on #194 that it would be nice to distinguish between "normal" stop events, and stop events triggered by the operating system killing the activity.

B: The actual scenario: neither the registered mediaStatus nor mediaError callbacks get called.

This is happening fairly inconsistently. It seems to work as expected if you start playing something, pause it, and immediately kill the activity. However, it tends to break if you pause the media, then open a bunch of other apps, lock/unlock the screens a few time, and then kill the activity. Even then, it's only breaking around 25% of the time for me.

I've tested this on an both Android 7.2 and Android 8.1 devices, but I'd expect it's happening elsewhere as well. I'm wondering if the plugin is even getting notified that the activity was destroyed in the onActivityDestroyed handler in the broken scenario.

Happy to provide additional information as needed.

iOS: Playback of mp3 stops audio of other apps

Hello,

I have created a cordova app for iOS and I use the media-plugin for playing short sfx-sounds. But whenever my app starts to playback an mp3 file it stops all other audio of the system and does not resume it afterwards.

In my case, spotify plays in the background and I want the sounds of my app to overlap that music.

Right now, I use this code:

var mediaRes = new Media(src, function onSuccess() { mediaRes.release(); }, function onError(e){}); mediaRes.play();
Is there any way to prevent my app from interfering with sounds of other apps?

Thank you very much! :)

iOS ringer status ignored after playing second sound

Bug Report

Problem

What is expected to happen?

When I activate the physical ringer (a.k.a. silent mode) switcher on the iPhone, I expect to hear no more sounds.

What does actually happen?

When loading the app, I start a background music track. As long as I don't play any other sound, switching the physical ringer switcher will turn off the background music.
However, as soon as I have played any other sound, the ringer switcher no longer turns off the music. Entirely closing the app and reopening it means the switcher works again, only as long as I don't do anything else.

Information

Command or Code

Not a command, as the ringer is handled automatically.
Sounds were played using loadSound and playSound, obviously.

Environment, Platform, Device

iOS 12.1.4, iPhone SE

Version information

Cordova 8.1.2
Cordova-plugin-media 5.0.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Playback stops after a while if app is on background or device is locked

On Oreo (Android 8.0+), playback stops after a while whenever app goes into background mode or device is locked, it's impossible to restore it by reloading app or unlocking device.

I´ve read that this can be fixed by implementing a Foreground Service, how could it be done?, any guidance will be great.

Add option to change Sampling- and Bitrate

The default sound quality is really bad (8kHz sampling rate).

Please add an option to let us change the EncodingBitRate and SamplingRate.

Android Example:

this.recorder.setAudioEncodingBitRate(192000);
this.recorder.setAudioSamplingRate(44100);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.