Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support audio file #37

Closed
francoisthi opened this issue Sep 3, 2015 · 1 comment
Closed

Support audio file #37

francoisthi opened this issue Sep 3, 2015 · 1 comment

Comments

@francoisthi
Copy link

hi,

i would like to send some audio file with this plugin but when i try.
it send audio file like picture.

like that :

var message = {
text: txtmms,
audio: "http://quoteit.fr/quote.mp3"
};

if (image != null && image.length() > 0) {
sendIntent.setType("image/*");
final URL url = new URL(image);
String storageDir = Environment.getExternalStorageDirectory().getPath();
final String path = storageDir + "/" + image.substring(image.lastIndexOf("/") + 1, image.length());
cordova.getThreadPool().execute(new Runnable() {
@OverRide
public void run() {
try {
saveImage(url, path);
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(path)));
cordova.getActivity().startActivityForResult(sendIntent, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} else {
sendIntent.setType("text/plain");
cordova.startActivityForResult(this, sendIntent, 0);
}
}

public static void saveImage(URL url, String outputPath) throws IOException {
    InputStream is = url.openStream();
    OutputStream os = new FileOutputStream(outputPath);
    byte[] b = new byte[2048];
    int length;
    while ((length = is.read(b)) != -1) {
        os.write(b, 0, length);
    }
    is.close();
    os.close();
}

How can i change that code for accept audio file from url ?

thx a lot.
Sorry for my french

@leecrossley
Copy link
Owner

The best way is to share the URL (this is your only option for iOS), e.g.

var message = {
    url: "http://quoteit.fr/quote.mp3"
};
socialmessage.send(message);

For Android, it may be possible to sendIntent.setType("audio/*");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants