【问题标题】:Share audio button分享音频按钮
【发布时间】:2017-03-17 12:05:50
【问题描述】:

我正在尝试创建一个 Android 应用程序,但我无法在单击按钮时“共享音频 .mp3”。这是我在 java 中的项目:

 Button buonaseeera = (Button) findViewById(R.id.pulsantebuonaseeera);
 buonaseeera.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v) {

                     audiobuonaseeera = MediaPlayer.create(getApplicationContext(),
                         R.raw.buonaseeeraaudio);
                     audiobuonaseeera.start();

                     Button sharebutton = (Button) findViewById(R.id.sharebutton);

                     sharebutton.setOnClickListener(new View.OnClickListener() {
                                 @Override
                                 public void onClick(View v) {

解决方案应该是什么?提前致谢。

【问题讨论】:

    标签: java android audio mp3 share


    【解决方案1】:

    在分享按钮的onClick() 中,添加以下代码:

    Intent shareAudioIntent = new Intent(Intent.ACTION_SEND);
    shareAudioIntent.setType("audio/mp3");
    shareAudioIntent.putExtra(Intent.EXTRA_STREAM,
                       Uri.parse("file://"+"path_to_your_mp3_file"));
    startActivity(Intent.createChooser(shareAudioIntent, "Share MP3 with:"));
    

    只需将“path_to_your_mp3_file”替换为您的音频路径即可。

    如果您想从资源文件夹共享文件,您必须先将其复制到存储,然后再从存储位置共享文件。

    快乐的编码。 !!!

    【讨论】:

    • 非常感谢。我去试试
    • 完美运行,但还有另一个问题:当我尝试共享音频文件并选择要与之共享的应用程序时,出现以下消息:不支持文件格式。但它是一个普通的 .mp3 文件。我能做什么?
    • 您要与哪个应用程序共享 mp3 文件?
    • 所有应用。每次我尝试分享它,我都不能
    • 如何分享?
    【解决方案2】:

    首先,据我了解,您正在尝试通过单击按钮来共享音频文件。使用此代码 sn-p 共享音频文件。只需在按钮单击功能中使用它。

    String sharePath = Environment.getExternalStorageDirectory().getPath()
                + "your mp3 path";
        Uri uri = Uri.parse(sharePath);
        Intent share = new Intent(Intent.ACTION_SEND);
        share.setType("audio/*");
        share.putExtra(Intent.EXTRA_STREAM, uri);
        startActivity(Intent.createChooser(share, "Share Audio File"));
    

    【讨论】:

    • 你在哪里写了“你的路径mp3”,我应该写什么?因为,如果我编写 mp3 文件的路径 (R.raw.buonaseeeraaudio),当我使用应用程序中的按钮时,它会显示消息:不支持文件格式。在 andvance 中谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-19
    相关资源
    最近更新 更多