具有4.4.4版本的Samsung SGH设备无法使用媒体播放器播放音频 [英] Samsung SGH device with 4.4.4 version.failed to play audio using media player

查看:82
本文介绍了具有4.4.4版本的Samsung SGH设备无法使用媒体播放器播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在Samsung GT-I93001中工作正常,同时在Samsung SGH-M919设备中给出以下错误.两者都具有相同的4.4.4版本.有人可以指出正确的方向吗?这是设备特定的错误吗?是什么原因?

This code is working fine in Samsung GT-I93001 while giving below error in Samsung SGH-M919 device.Both have same 4.4.4 version.Can someone point me in right direction.Is this device specific error?What is the reason?

private final String AUDIO_URL = " http://techslides.com/demos/samples/sample.mp3 ";
    this is the issue only in one device.
     public void playAudio()
        {
            mediaPlayer = new MediaPlayer();
            try {
                mediaPlayer.reset();
                mediaPlayer.setDataSource(AUDIO_URL);
                mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                mediaPlayer.prepare();
                mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
                    public void onPrepared(MediaPlayer mp) {
                        mp.start();
                    }
                });
            } catch (IllegalArgumentException e) {
                Log.d(MainActivity.class.getName(), "IllegalArgumentException:" );
                e.printStackTrace();
            } catch (IllegalStateException e) {
                Log.d(MainActivity.class.getName(), "IllegalStateException:" );
                e.printStackTrace();
            } catch (IOException e) {
                Log.d(MainActivity.class.getName(), "IOException:" );
                Toast.makeText(MainActivity.this, "str_error_io_exception", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }

请检查logcat错误:

Please check logcat errors:

Logcat:

   V/MediaPlayer-JNI: native_setup
        01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: constructor
        01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: setListener
        01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer-JNI: reset
        01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: reset
        01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: message received msg=8, ext1=0, ext2=0
01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer-JNI: setAudioStreamType: 3
        01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: MediaPlayer::setAudioStreamType
        01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: setVideoSurfaceTexture
        01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: prepare
        01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: unrecognized message: (8, 0, 0)
        01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: callback application
        01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: back from callback
        01-03 09:32:23.050 22239-22251/com.example.abc V/MediaPlayer: message received msg=100, ext1=1, ext2=-1004
        01-03 09:32:23.060 22239-22251/com.example.abc E/MediaPlayer: error (1, -1004)
        01-03 09:32:23.060 22239-22251/com.example.abc V/MediaPlayer: signal application thread
        01-03 09:32:23.060 22239-22239/com.example.abc V/MediaPlayer: prepare complete - status=1
        01-03 09:32:23.060 22239-22239/com.example.abc D/com.example.abc.MainActivity: IOException:
        01-03 09:32:23.060 22239-22239/com.example.abc D/Toast:  checkMirrorLinkEnabled returns : false
        01-03 09:32:23.060 22239-22239/com.example.abc D/Toast: showing allowed
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: java.io.IOException: Prepare failed.: status=0x1
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.media.MediaPlayer.prepare(Native Method)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at com.example.abc.MainActivity.playAudio(MainActivity.java:56)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at com.example.abc.MainActivity$2.onClick(MainActivity.java:44)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.view.View.performClick(View.java:4753)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.view.View$PerformClick.run(View.java:19562)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.os.Handler.handleCallback(Handler.java:733)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.os.Looper.loop(Looper.java:146)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5635)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
        01-03 09:32:23.060 22239-22239/com.example.abc W/System.err:     at dalvik.system.NativeStart.main(Native Method)

推荐答案

检查此代码

if (mediaPlayer == null) {
                        mediaPlayer = new MediaPlayer();
                        mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {
                                mediaPlayer.reset();
                            }
                        });
                    }
                    if (mediaPlayer.isPlaying()) {
                        mediaPlayer.stop();
                        mediaPlayer.reset();
                    }
mediaPlayer.setDataSource(audioUrl);
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.prepare();
            mediaPlayer.start();

                        }
                    });
                }
                if (mediaPlayer.isPlaying() && currentPlaying == getAdapterPosition()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                }

这篇关于具有4.4.4版本的Samsung SGH设备无法使用媒体播放器播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆