• 5828阅读
  • 6回复

用android编写播放器画面无法显示的问题 [复制链接]

上一主题 下一主题
离线kldxxlxc
 

只看楼主 倒序阅读 使用道具 楼主  发表于: 2016-12-14
我用SDK里面提供的jar包编写了一个播放器,但是打开一个网络流之后一直是黑屏的,无法播放,但是我用log.i()调试输出了open()的返回值和play()的返回值,都是0,那说明应该是播放成功了,但就是没有画面,我设置了setview,界面是一个surfaceview,实在是不知道哪里出了问题,代码的截图如下:
离线helloworld

只看该作者 沙发  发表于: 2016-12-22
package com.example.test.aplayersimpledemo;

import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;

import com.aplayer.aplayerandroid.APlayerAndroid;

import static com.example.test.aplayersimpledemo.MainActivity.PAUSE_REASON.*;

public class MainActivity extends AppCompatActivity {
    private SurfaceView     videoPlayView;
    private Button          playButton;
    private Button          pauseButton;
    private Button          stopButton;
    private APlayerAndroid  aPlayerAndroid;
    private String          mediaPath;

    public enum PAUSE_REASON{ PAUSE_UNKNOW, PAUSE_SYSTEM_CALL, PAUSE_USER_CALL};
    private PAUSE_REASON     pauseReason = PAUSE_UNKNOW;      //是否是Activity切换,导致进入后台暂停

    private static final String LOG_MODULE_TAGE = "AplayerSampleDemo";

    private static int  APLYER_OPRATION_SUCCESS = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        videoPlayView = (SurfaceView) findViewById(R.id.surfaceView);
        playButton    = (Button) findViewById(R.id.play_button);
        pauseButton    = (Button) findViewById(R.id.pause_button);
        stopButton    = (Button) findViewById(R.id.stop_button);

        mediaPath     = "http://aplayer.open.xunlei.com/test.rmvb";
        aPlayerAndroid = new APlayerAndroid();

        aPlayerAndroid.setView(videoPlayView);
        registerUILister();
        registerAplayerLister();
    }

    private void registerUILister()
    {
        playButton.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v) {
                int playerState = aPlayerAndroid.getState();
                if(APlayerAndroid.PlayerState.APLAYER_PAUSING == playerState ||
                   APlayerAndroid.PlayerState.APLAYER_PAUSED  == playerState  ) {
                    aPlayerAndroid.play();
                }

                if(APlayerAndroid.PlayerState.APLAYER_READ == playerState ) {
                    if(APLYER_OPRATION_SUCCESS != aPlayerAndroid.open(mediaPath)) {
                        Log.e(LOG_MODULE_TAGE, "Open Failed: "  + mediaPath);
                    }
                }
            }
        });

        pauseButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int playerState = aPlayerAndroid.getState();
                if(APlayerAndroid.PlayerState.APLAYER_PLAYING == playerState ||
                    APlayerAndroid.PlayerState.APLAYER_PLAY  == playerState  ) {
                    if(APLYER_OPRATION_SUCCESS != aPlayerAndroid.pause())
                    {
                        Log.e(LOG_MODULE_TAGE, "Call Pause Failed");
                    }

                    pauseReason = PAUSE_USER_CALL;
                }
            }
        });

        stopButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int playerState = aPlayerAndroid.getState();
                if(APlayerAndroid.PlayerState.APLAYER_CLOSEING != playerState && APLYER_OPRATION_SUCCESS != aPlayerAndroid.close())
                {
                    Log.e(LOG_MODULE_TAGE, "Call Pause Failed");
                }

                videoPlayView.setVisibility(View.GONE);
                videoPlayView.setVisibility(View.VISIBLE);
            }
        });

    }


    private void registerAplayerLister()
    {
        aPlayerAndroid.setOnOpenCompleteListener(new APlayerAndroid.OnOpenCompleteListener() {
            @Override
            public void onOpenComplete(boolean b) {
                String openResultStr = b ? "Success" : "Failed";
                Log.i(LOG_MODULE_TAGE, "Open Complete, Reasult is " + openResultStr);
            }
        });

        aPlayerAndroid.setOnOpenSuccessListener(new APlayerAndroid.OnOpenSuccessListener() {
            @Override
            public void onOpenSuccess() {
                aPlayerAndroid.play();
            }
        });
    }


    @Override
    protected void onPause() {
        if(PAUSE_USER_CALL != pauseReason){
            pauseReason = PAUSE_SYSTEM_CALL;
        }
        aPlayerAndroid.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {

        videoPlayView.setVisibility(View.GONE);
        videoPlayView.setVisibility(View.VISIBLE);

        if(null != aPlayerAndroid && aPlayerAndroid.getState() == APlayerAndroid.PlayerState.APLAYER_PAUSED
                && PAUSE_SYSTEM_CALL == pauseReason )
        {
            aPlayerAndroid.play();
        }
        pauseReason = PAUSE_UNKNOW;

        super.onResume();
    }

    @Override
    protected void onDestroy() {
        aPlayerAndroid.destroy();
        aPlayerAndroid = null;
        super.onDestroy();
    }
}
离线woyehua

只看该作者 板凳  发表于: 2016-12-25
回 helloworld 的帖子
helloworld:package com.example.test.aplayersimpledemo;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
....... (2016-12-22 14:09)


按照你的方法有问题,这是怎么回事,我试着禁用字幕显示也是这样。
I/APlayerAndroid: native GetState enter obj_id = 0
I/APlayerAndroid: native Open enter obj_id = 0
I/APlayerAndroid: APlayerAndroid::_open enter m_file_url = http://www.stormbirds.cn/test.mp4
E/APlayerAndroid: APlayerAndroid::_open m_http_header =
E/APlayerAndroid: APlayerAndroid::_open avformat_open_input failed
I/APlayerAndroid: APlayerAndroid::PlayComplete PLAYRE_RESULT = -2147483647
E/APlayerAndroid: AttachCurrentThread to obtain JNIEnv
E/APlayerAndroid: APlayerAndroid::_open Leave return E_FAILED
I/APlayerAndroid: APlayerAndroid::_close enter
I/APlayerAndroid: APlayerAndroid::_close m_aplayer_v_decoder_render stop
E/APlayerAndroid: AttachCurrentThread to obtain JNIEnv
I/APlayerAndroid: APlayerAndroid::_close m_aplayer_sub_decoder_render stop
I/APlayerAndroid: APlayerAndroid::_close m_audio_decoder stop
I/APlayerAndroid: APlayerARenderSLES::Stop enter
I/APlayerAndroid: APlayerARenderSLES::Stop leave
I/APlayerAndroid: APlayerAndroid::_close m_audio_render_opensles stop
I/APlayerAndroid: APlayerParser::Stop Enter
I/APlayerAndroid: APlayerAndroid::_close m_parser stop
E/APlayerAndroid: AttachCurrentThread to obtain JNIEnv
I/APlayerAndroid: APlayerAndroid::_close leave
E/APlayerAndroid: ShowSubtitle
E/APlayerAndroid: ShowSubtitle mSubtitleViewTop = 708 textViewHeight =  47

离线sanchibing

只看该作者 地板  发表于: 2017-01-06
我的也会和你的情况一样,不知道什么情况,偶然出现的,有的时间就正常。
离线wtl3ull

只看该作者 4楼 发表于: 2017-01-09
楼主解决了么?我也是这样的诶
asdasdasd
离线liuji109

只看该作者 5楼 发表于: 2017-01-17
怎么样?
离线lxcuntest

只看该作者 6楼 发表于: 2017-05-29
你用的是百度SDK还是迅雷
aaaaaaaaaaa
快速回复
限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
上一个 下一个