Android 中的流媒体音频

发布于 2024-11-07 12:26:08 字数 1616 浏览 0 评论 0原文

我使用此代码来传输音频。但它没有奏效。

    public class MediaPlayerAudio extends Activity implements OnClickListener,
       OnPreparedListener, OnErrorListener {

          MediaPlayer mp;

          public v

oid onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button bt = (Button)findViewById(R.id.play);
          bt.setOnClickListener(this);
      }



      @Override
         public void onPrepared(MediaPlayer mp) {
             Log.i("radio", "prepare finished");
             mp.start();

         }


        @Override
        public void onClick(View v) {
             try
              {
                  mp = new MediaPlayer();
                  mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
                  mp.setOnPreparedListener(this);
                  mp.setOnErrorListener(this);
                  mp.setDataSource("http://stream1.tanitweb.com/rtci");
                  mp.prepareAsync();
              }
              catch(Exception e)
              {
                  Log.e("radio", e.getMessage());
              }

        }



        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            return false;
        }

      }}

单击按钮时出现此错误

05-15 09:31:14.360: ERROR/PlayerDriver(30): Command PLAYER_INIT completed with an error or info PVMFErrCorrupt
05-15 09:31:14.371: ERROR/MediaPlayer(330): error (1, -10)
05-15 09:31:14.371: ERROR/MediaPlayer(330): Error (1,-10)

I use this code to stream an audio. But it didn't worked.

    public class MediaPlayerAudio extends Activity implements OnClickListener,
       OnPreparedListener, OnErrorListener {

          MediaPlayer mp;

          public v

oid onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
          Button bt = (Button)findViewById(R.id.play);
          bt.setOnClickListener(this);
      }



      @Override
         public void onPrepared(MediaPlayer mp) {
             Log.i("radio", "prepare finished");
             mp.start();

         }


        @Override
        public void onClick(View v) {
             try
              {
                  mp = new MediaPlayer();
                  mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
                  mp.setOnPreparedListener(this);
                  mp.setOnErrorListener(this);
                  mp.setDataSource("http://stream1.tanitweb.com/rtci");
                  mp.prepareAsync();
              }
              catch(Exception e)
              {
                  Log.e("radio", e.getMessage());
              }

        }



        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            // TODO Auto-generated method stub
            return false;
        }

      }}

On click in the button, I have this error

05-15 09:31:14.360: ERROR/PlayerDriver(30): Command PLAYER_INIT completed with an error or info PVMFErrCorrupt
05-15 09:31:14.371: ERROR/MediaPlayer(330): error (1, -10)
05-15 09:31:14.371: ERROR/MediaPlayer(330): Error (1,-10)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

提笔书几行 2024-11-14 12:26:08

Android 似乎不支持您尝试播放的媒体格式。 这里是包含所有支持格式的表格,看来 ASF 是不在其中。我已经尝试过你的网址,它指向 rtci.asf

It seems that media format you're trying to play is not supported from android. Here is table with all supported formats and it seems that ASF is not in it. I've tried your url and it's pointing to rtci.asf

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文