安卓的MediaPlayer工作正常,在自定义音频流媒体应用起来到Android 2.1,但不是在更高版本是在、更高、自定义、流媒体

2023-09-11 11:01:55 作者:心怀孤勇

编辑:

Android 2.2 MediaPlayer正在工作的罚款有一个Shoutcast一样的网址,但不与另一个

我需要从外部URL(Shoutcast的流)播放的音频文件。目前的音频文件增量和放大器下载;是因为我们得到足够的声音在电话本地临时存储,尽快发挥。我现在用的StreamingMediaPlayer类。

检查这一块的code:

 私人的MediaPlayer createMediaPlayer(文件媒体文件)
            抛出IOException异常{
        MediaPlayer的MPLAYER =新的MediaPlayer();
        //例如媒体文件的= /数据/数据​​/包/缓存/ playingMedia0.dat
        的FileInputStream FIS =新的FileInputStream(媒体文件);
        mPlayer.setDataSource(fis.getFD());
        MPLAYER prepare()。
        返回MPLAYER;
    }
 

当前状态:

1 - 它工作正常,从Android 1.6的到2.1,但不是在更高的版本一样的Andr​​oid 2.2。

2-mPlayer.setDataSource(fis.getFD())是引发错误的行。

3的错误是无法创建媒体播放器

Windows Server 2003windows media player

其他解决方案的尝试:

我想下面替代的解决方案,但没有那么远的工作。

Android 2.2 MediaPlayer正在工作的罚款有一个Shoutcast一样的网址,但不与另一个

我在找什么?

我的目标是有code和平可以在Android 2.1及功放工作;更高。

这个问题也是在这里讨论:

1 不一致的2.2媒体播放器的行为

2 - 安卓code为2.2 流Shoutcast的流断裂

3这个问题在很多本网站上的问题也讨论过,但我找到了答案没有在那里。

4- markmail.org

LogCat中跟踪:

 无法创建媒体播放器
错误复制缓冲conent。
显示java.lang.NullPointerException
com.ms.iradio.StreamingMediaPlayer.startMediaPlayer(StreamingMediaPlayer.java:251)
com.ms.iradio.StreamingMediaPlayer.access $ 2(StreamingMediaPlayer.java:221)
com.ms.iradio.StreamingMediaPlayer $ 2.运行(StreamingMediaPlayer.java:204)
android.os.Handler.handleCallback(Handler.java:587)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:123)
android.app.ActivityThread.main(ActivityThread.java:3683)
java.lang.reflect.Method.invokeNative(本机方法)
java.lang.reflect.Method.invoke(Method.java:507)
com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
dalvik.system.NativeStart.main(本机方法)
 

解决方案

StreamingMediaPlayer 类是使用双缓冲技术来绕过在pre-限制1.2版本的Andr​​oid。 Android操作系统的所有生产排放的措施已经包括了MediaPlayer的一个支持流媒体(1)。我建议使用这种双缓冲技术来解决这个问题这样做,而不是。

Android操作系统2.2取代了旧的媒体播放器code与FrightCast播放器,可能是不同的作用在这种情况下。

在你的堆栈跟踪行号没有映射到你链接到的文件,所以我认为有,你实际上正在使用一个不同的版本。我要去猜测,即 NullPointerException异常正在报告的MediaPlayer 但无论是的FileInputStream ,也没有返回的FileDescriptor 可以是

(1)在此之前2.2版本的媒体播放器将不承认Shoutcast的响应结果中的ICY / 1.1版头流。通过创建一个代理,这个替换用HTTP / 1.1可以解决这个问题。请参阅此处为例StreamProxy类。

EDIT:

Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one

I need to play audio files from external URLs(shoutcast stream). Currently the audio files are downloaded incrementally & are played as soon as we get enough audio in phone local temporary storage. i am using the StreamingMediaPlayer class.

Check this piece of code:

    private MediaPlayer createMediaPlayer(File mediaFile)
            throws IOException {
        MediaPlayer mPlayer = new MediaPlayer();
        //example of mediaFile =/data/data/package/cache/playingMedia0.dat
        FileInputStream fis = new FileInputStream(mediaFile);
        mPlayer.setDataSource(fis.getFD());
        mPlayer.prepare();
        return mPlayer;
    }

Current status:

1- It works fine from Android 1.6 to 2.1 but not in the higher versions like Android 2.2.

2- The "mPlayer.setDataSource(fis.getFD())" is the line which throws the error.

3- The error is "Unable to to create media player"

Other Solution tried:

I tried below alternate solution but nothing worked so far.

Android 2.2 MediaPlayer is working fine with one SHOUTcast URL but not with the other one

What i am looking for?

My goal is to have a peace of code which can work on Android 2.1 & higher.

This issue is also discussed here:

1- Inconsistent 2.2 Media Player Behavior

2- android code for streaming shoutcast stream breaks in 2.2

3- This issue is also discussed in a lot of questions on this site, but i found the answer no where.

4- markmail.org

LogCat trace:

Unable to to create media player
Error copying buffered conent.
java.lang.NullPointerException
com.ms.iradio.StreamingMediaPlayer.startMediaPlayer(StreamingMediaPlayer.java:251)
com.ms.iradio.StreamingMediaPlayer.access$2(StreamingMediaPlayer.java:221)
com.ms.iradio.StreamingMediaPlayer$2.run(StreamingMediaPlayer.java:204)
android.os.Handler.handleCallback(Handler.java:587)
android.os.Handler.dispatchMessage(Handler.java:92)
android.os.Looper.loop(Looper.java:123)
android.app.ActivityThread.main(ActivityThread.java:3683)
java.lang.reflect.Method.invokeNative(Native Method)
java.lang.reflect.Method.invoke(Method.java:507)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
dalvik.system.NativeStart.main(Native Method)

解决方案

The StreamingMediaPlayer class is using a double-buffering technique to get around limitations in pre-1.2 releases of Android. All production releases of Android OS have included a MediaPlayer that supports streaming media(1). I would recommend doing that rather than using this double-buffering technique to get around the problem.

Android OS 2.2 replaced the old media player code with the FrightCast player which probably is acting differently in this case.

The line numbers in your stack trace don't map to the file you link to, so I assume there's a different version that you're actually using. I'm going to guess that that NullPointerException is being reported by MediaPlayer but neither the FileInputStream nor the returned FileDescriptor can be null.

(1) Prior to version 2.2 the media player wouldn't recognize ShoutCast streams with an "ICY/1.1" version header in the response. By creating a proxy that replaces this with "HTTP/1.1" you can resolve that. See the StreamProxy class here for an example.