SmartPlayer.java 23.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755
/*
 * SmartPlayer.java
 * SmartPlayer
 * 
 * Github: https://github.com/daniulive/SmarterStreaming
 * WebSite: http://www.daniulive.com
 *
 * Created by DaniuLive on 2015/09/26.
 * Copyright © 2014~2017 DaniuLive. All rights reserved.
 */

package com.daniulive.smartplayer;

import java.nio.ByteBuffer;

import android.app.Activity;  
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceView;
  
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.eventhandle.SmartEventCallback;
import com.videoengine.*;

public class SmartPlayer extends Activity {
	    
    private SurfaceView sSurfaceView = null;   
	
	private long playerHandle = 0;
	
	private static final int PORTRAIT = 1;		//竖屏
	private static final int LANDSCAPE = 2;		//横屏
	private static final String TAG = "SmartPlayer";
	
	private SmartPlayerJni libPlayer = null;
	
	private int currentOrigentation = PORTRAIT;
	
	private boolean isPlaybackViewStarted = false;
	
	private String playbackUrl = null;
	
	private boolean isMute = false;
	
	private boolean isHardwareDecoder = false;
	
	Button btnPopInputText;
	Button btnPopInputUrl;
	Button btnMute;
    Button btnStartStopPlayback;
	Button btnHardwareDecoder;
    TextView txtCopyright;
    TextView txtQQQun;
    
    LinearLayout lLayout = null;
    FrameLayout fFrameLayout = null;
    
    private Context myContext;
	String url="rtmp://player.daniulive.com:1935/hls/stream";
	static {  
		System.loadLibrary("SmartPlayer");
	}
  
    @Override protected void onCreate(Bundle icicle) {  
        super.onCreate(icicle);  
         url=getIntent().getStringExtra("url");
      Log.i(TAG, "Run into OnCreate++");
      Log.e("URl",url+"");
      libPlayer = new SmartPlayerJni();
         
      myContext = this.getApplicationContext();

	  boolean bViewCreated = CreateView();
	    
	   if(bViewCreated){
		   inflateLayout(LinearLayout.VERTICAL);
	   }
    }
    
    /* For smartplayer demo app, the url is based on: baseURL + inputID
     * For example: 
     * baseURL: rtmp://player.daniulive.com:1935/hls/stream
     * inputID: 123456 
     * playbackUrl: rtmp://player.daniulive.com:1935/hls/stream123456
     * */
    private void GenerateURL(String id){
    	if(id == null)
    		return;
    	
    	if(id.equals("hks"))
    	{
    		playbackUrl = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
    		return;
    	}
    	
    	btnStartStopPlayback.setEnabled(true);
//    	String baseURL = "rtmp://player.daniulive.com:1935/hls/stream";
    	String baseURL = url;

    	playbackUrl = baseURL + id;
    }
    
    private void SaveInputUrl(String url)
    {
    	playbackUrl = "";
    	
    	if ( url == null )
    		return;
    	
    	// rtmp:/
    	if ( url.length() < 8 )
    	{
    		Log.e(TAG, "Input full url error:" + url);
    		return;
    	}
    	
    	if ( !url.startsWith("rtmp://") && !url.startsWith("rtsp://"))
    	{
    	    Log.e(TAG, "Input full url error:" + url);
    		return;
    	}
    		
    	btnStartStopPlayback.setEnabled(true);
    	playbackUrl = url;
    	
    	 Log.i(TAG, "Input full url:" + url);
    }
    
    /* Popup InputID dialog */
    private void PopDialog(){
    	final EditText inputID = new EditText(this);
    	inputID.setFocusable(true);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("如 rtmp://player.daniulive.com:1935/hls/stream123456,请输入123456").setView(inputID).setNegativeButton(
                "取消", null);
        builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
//                        String strID = inputID.getText().toString() ;
						String strID = url;
                    	GenerateURL(strID);
                    }
                });
        builder.show();
    }
    
    
    private void PopFullUrlDialog(){
    	final EditText inputUrlTxt = new EditText(this);
    	inputUrlTxt.setFocusable(true);
    	inputUrlTxt.setText(url+"");

        AlertDialog.Builder builderUrl = new AlertDialog.Builder(this);
        builderUrl.setTitle(""+url).setView(inputUrlTxt).setNegativeButton(
                "取消", null);
        builderUrl.setPositiveButton("确认", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
						//TODO 这个位置是修改的
                        String fullUrl =url;
//                        String fullUrl = inputUrlTxt.getText().toString();
                        SaveInputUrl(fullUrl);
                    }
                });
        builderUrl.show();
    }
    
    /* Generate basic layout */
    private void inflateLayout(int orientation) {
    	if (null == lLayout)
            lLayout = new LinearLayout(this);

	    addContentView(lLayout,  new LayoutParams(LayoutParams.WRAP_CONTENT,
	      LayoutParams.WRAP_CONTENT));
    	
        lLayout.setOrientation(orientation);
   
        fFrameLayout = new FrameLayout(this);
        
        LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT, 1.0f);
        fFrameLayout.setLayoutParams(lp);
        Log.i(TAG, "++inflateLayout..");
               
        sSurfaceView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));       
        
        fFrameLayout.addView(sSurfaceView, 0);

        RelativeLayout outLinearLayout = new RelativeLayout(this);
        outLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
        
        LinearLayout lLinearLayout = new LinearLayout(this);
        lLinearLayout.setOrientation(LinearLayout.VERTICAL);
        lLinearLayout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
 
                
        LinearLayout copyRightLinearLayout = new LinearLayout(this);
        copyRightLinearLayout.setOrientation(LinearLayout.VERTICAL);
        RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        rl.topMargin = getWindowManager().getDefaultDisplay().getHeight()-270;
        copyRightLinearLayout.setLayoutParams(rl);
 
        txtCopyright=new TextView(this);
        txtCopyright.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        txtCopyright.setText("Copyright 2014~2016 www.daniulive.com v1.0.16.0326");
        copyRightLinearLayout.addView(txtCopyright, 0);
        		
        txtQQQun=new TextView(this);
        txtQQQun.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        txtQQQun.setText("学点云");
        copyRightLinearLayout.addView(txtQQQun, 1);
        
        /* PopInput button */
        btnPopInputText = new Button(this);
        btnPopInputText.setText("输入urlID");
        btnPopInputText.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        lLinearLayout.addView(btnPopInputText, 0);
        
        btnPopInputUrl = new Button(this);
        btnPopInputUrl.setText("输入完整url");
        btnPopInputUrl.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        lLinearLayout.addView(btnPopInputUrl, 1);
        
        /*mute button */
        isMute = false;
        btnMute = new Button(this);
        btnMute.setText("静音 ");
        btnMute.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        lLinearLayout.addView(btnMute, 2);
        
        /*hardware decoder button */
        isHardwareDecoder = false;
        btnHardwareDecoder = new Button(this);
        btnHardwareDecoder.setText("当前软解码");
        btnHardwareDecoder.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        lLinearLayout.addView(btnHardwareDecoder, 3);
        
        /* Start playback stream button */
        btnStartStopPlayback = new Button(this);
        btnStartStopPlayback.setText("开始播放 ");
        btnStartStopPlayback.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        lLinearLayout.addView(btnStartStopPlayback, 4);
 
       
        outLinearLayout.addView(lLinearLayout, 0);
        outLinearLayout.addView(copyRightLinearLayout, 1);
        fFrameLayout.addView(outLinearLayout, 1);

        lLayout.addView(fFrameLayout, 0);
  
        if(isPlaybackViewStarted)
        {
        	btnPopInputText.setEnabled(false);
        	btnPopInputUrl.setEnabled(false);
        	btnHardwareDecoder.setEnabled(false);
        	btnStartStopPlayback.setText("停止播放 ");
        }
        else
        {
        	btnPopInputText.setEnabled(true);
        	btnPopInputUrl.setEnabled(true);
        	btnHardwareDecoder.setEnabled(true);
        	btnStartStopPlayback.setText("开始播放 ");
        }
        
        /* PopInput button listener */
        btnPopInputText.setOnClickListener(new Button.OnClickListener() {  
        	  
            //  @Override  
              public void onClick(View v) {  
            	  Log.i(TAG, "Run into input playback ID++");
	              
            	  PopDialog();
            	  
            	  Log.i(TAG, "Run out from input playback ID--");
              	}
              });  
        
        
        btnPopInputUrl.setOnClickListener(new Button.OnClickListener() { 
        	 public void onClick(View v) { 
        		 PopFullUrlDialog();
        	 }
        });
        
        btnMute.setOnClickListener(new Button.OnClickListener() 
        { 
       	 public void onClick(View v) { 
    		 isMute = !isMute;
    		 
    		 if ( isMute )
    		 {
    			 btnMute.setText("取消静音");
    		 }
    		 else
    		 {
    			 btnMute.setText("静音");
    		 }
    		 
    		 if ( playerHandle != 0 )
    		 {
    			 libPlayer.SmartPlayerSetMute(playerHandle, isMute?1:0);
    		 }
    	 }
       });

        btnHardwareDecoder.setOnClickListener(new Button.OnClickListener() 
        { 
       	 public void onClick(View v) { 
    		 isHardwareDecoder = !isHardwareDecoder;
    		 
    		 if ( isHardwareDecoder )
    		 {
    			 btnHardwareDecoder.setText("当前硬解码");
    		 }
    		 else
    		 {
    			 btnHardwareDecoder.setText("当前软解码");
    		 }
    		 
    	 }
       });
        
        btnStartStopPlayback.setOnClickListener(new Button.OnClickListener() {  
        	  
            //  @Override  
              public void onClick(View v) {  
	              
            	  if(isPlaybackViewStarted)
            	  {
                	  Log.i(TAG, "Stop playback stream++");
            		  btnStartStopPlayback.setText("开始播放 ");
            		  btnPopInputText.setEnabled(true);
            		  btnPopInputUrl.setEnabled(true);
            		  btnHardwareDecoder.setEnabled(true);
            		  libPlayer.SmartPlayerClose(playerHandle);	
            		  playerHandle = 0;
            		  isPlaybackViewStarted = false;
                      Log.i(TAG, "Stop playback stream--");
            	  }
            	  else
            	  {
            		  Log.i(TAG, "Start playback stream++");
            		  
            		  playerHandle = libPlayer.SmartPlayerInit(myContext);
            	      
            	      if(playerHandle == 0)
            	      {
            	    	  Log.e(TAG, "surfaceHandle with nil..");
            	    	  return;
            	      }
            		  
					  libPlayer.SetSmartPlayerEventCallback(playerHandle, new EventHande());
					  
            	      libPlayer.SmartPlayerSetSurface(playerHandle, sSurfaceView); 	//if set the second param with null, it means it will playback audio only..
            		  	
            	      // libPlayer.SmartPlayerSetSurface(playerHandle, null); 
            	      
            	      // External Render test
            	      //libPlayer.SmartPlayerSetExternalRender(playerHandle, new RGBAExternalRender());
            	      //libPlayer.SmartPlayerSetExternalRender(playerHandle, new I420ExternalRender());
 	              	 
            	      libPlayer.SmartPlayerSetAudioOutputType(playerHandle, 0);
            	      
            	      libPlayer.SmartPlayerSetBuffer(playerHandle, 200);
            	      
            	      if ( isMute )
            	      {
            	    	  libPlayer.SmartPlayerSetMute(playerHandle, isMute?1:0);
            	      }
            	      
            	      if( isHardwareDecoder )
            	      {
            	    	  Log.i(TAG, "check isHardwareDecoder: " + isHardwareDecoder);
            	    	  
                	      int hwChecking = libPlayer.SetSmartPlayerVideoHWDecoder(playerHandle, isHardwareDecoder?1:0);
  						
    					  Log.i(TAG, "[daniulive] hwChecking: " + hwChecking);
            	      }

            	      //It only used when playback RTSP stream..
            	     // libPlayer.SmartPlayerSetRTSPTcpMode(playerHandle, 1);
     
					  //playbackUrl = "rtmp://live.hkstv.hk.lxdns.com/live/hks";
            	                  	      
            	      //playbackUrl = "rtsp://rtsp-v3-spbtv.msk.spbtv.com/spbtv_v3_1/214_110.sdp";

					  //playbackUrl = "rtmp://10.2.68.91:1935/hls/stream8";

	              	  if(playbackUrl == null){
	              		 Log.e(TAG, "playback URL with NULL..."); 
	              		 return;
	              	  }
	              	  
	              	  int iPlaybackRet = libPlayer.SmartPlayerStartPlayback(playerHandle, playbackUrl);
	              	  	              	  
	                  if(iPlaybackRet != 0)
	                  {
	                	 Log.e(TAG, "StartPlayback strem failed.."); 
	                	 return;
	                  }
	
	        		  btnStartStopPlayback.setText("停止播放 ");
	                  btnPopInputText.setEnabled(false);
	                  btnPopInputUrl.setEnabled(false);
	                  btnHardwareDecoder.setEnabled(false);
	              	  isPlaybackViewStarted = true;
	              	  Log.i(TAG, "Start playback stream--");
	        	  }
	          	}
              });
	}
	
    
    public static final String bytesToHexString(byte[] buffer)
    {   
        StringBuffer sb = new StringBuffer(buffer.length);   
        String temp;
        
        for (int i = 0; i < buffer.length; ++i)
        {   
        	temp = Integer.toHexString(0xff&buffer[i]);   
          if (temp.length() < 2)   
            sb.append(0);
          
          sb.append(temp);   
        }   
        
        return sb.toString();   
    }  
    
    class RGBAExternalRender implements NTExternalRender 
    {
    	//public static final int NT_FRAME_FORMAT_RGBA = 1;
    	//public static final int NT_FRAME_FORMAT_ABGR = 2;
    	//public static final int NT_FRAME_FORMAT_I420 = 3;
    	
    	private int width_ = 0;
    	private int height_ = 0;
    	private int row_bytes_ = 0;
    	private ByteBuffer rgba_buffer_ = null;

    	@Override
    	public int getNTFrameFormat()
    	{
    		Log.i(TAG, "RGBAExternalRender::getNTFrameFormat return "+ NT_FRAME_FORMAT_RGBA);
    		return NT_FRAME_FORMAT_RGBA;
    	}

    	@Override
    	public void onNTFrameSizeChanged(int width, int height)
    	{
    		width_ = width;
    		height_ = height;
    		
    		row_bytes_ = width_ * 4;
    		
    		Log.i(TAG, "RGBAExternalRender::onNTFrameSizeChanged width_:" + width_ + " height_:" + height_);
    		
    		rgba_buffer_ = ByteBuffer.allocateDirect(row_bytes_*height_);
    	}

    	@Override
    	public ByteBuffer getNTPlaneByteBuffer(int index)
    	{
    		if ( index == 0 )
    		{
    			return rgba_buffer_;
    		}
    		else
    		{
    			Log.e(TAG, "RGBAExternalRender::getNTPlaneByteBuffer index error:" + index);
    			return null;
    		}
    	}

    	@Override
    	public int getNTPlanePerRowBytes(int index)
    	{
    		if ( index == 0 )
    		{
    			return row_bytes_;
    		}
    		else
    		{
    			Log.e(TAG, "RGBAExternalRender::getNTPlanePerRowBytes index error:" + index);
    			return 0;
    		}
    	}

    	public void onNTRenderFrame()
    	{
    		 if( rgba_buffer_ == null )
    	            return;
    		 
    		 rgba_buffer_.rewind();
    		 
    		 // copy buffer
    		 
    		 // test
    		// byte[] test_buffer = new byte[16];
    		// rgba_buffer_.get(test_buffer);
    		 
    		 //Log.i(TAG, "RGBAExternalRender:onNTRenderFrame rgba:" + bytesToHexString(test_buffer));
    	}
    }
    
    class I420ExternalRender implements NTExternalRender
    {
    	//public static final int NT_FRAME_FORMAT_RGBA = 1;
    	//public static final int NT_FRAME_FORMAT_ABGR = 2;
    	//public static final int NT_FRAME_FORMAT_I420 = 3;
    	
    	private int width_ = 0;
    	private int height_ = 0;
    	
    	private int y_row_bytes_ = 0;
    	private int u_row_bytes_ = 0;
    	private int v_row_bytes_ = 0;
    	
    	private ByteBuffer y_buffer_ = null;
    	private ByteBuffer u_buffer_ = null;
    	private ByteBuffer v_buffer_ = null; 
    	
    	@Override
    	public int getNTFrameFormat()
    	{
    		Log.i(TAG, "I420ExternalRender::getNTFrameFormat return "+ NT_FRAME_FORMAT_I420);
    		return NT_FRAME_FORMAT_I420;
    	}

    	@Override
    	public void onNTFrameSizeChanged(int width, int height)
    	{
    		width_ = width;
    		height_ = height;
    		
    		y_row_bytes_ = (width_ + 15) & (~15);
    		u_row_bytes_ = ((width_+1)/2 + 15) & (~15);
    		v_row_bytes_ = ((width_+1)/2 + 15) & (~15);
    		
    		y_buffer_ = ByteBuffer.allocateDirect(y_row_bytes_*height_);
    		u_buffer_ = ByteBuffer.allocateDirect(u_row_bytes_*(height_+1)/2);
    		v_buffer_ = ByteBuffer.allocateDirect(v_row_bytes_*(height_+1)/2);
    		
    		Log.i(TAG, "I420ExternalRender::onNTFrameSizeChanged width_=" 
    		    + width_ + " height_=" + height_ 
    		    + " y_row_bytes_=" +  y_row_bytes_
    		    + " u_row_bytes_=" + u_row_bytes_
    		    + " v_row_bytes_=" + v_row_bytes_);
    	}

    	@Override
    	public ByteBuffer getNTPlaneByteBuffer(int index)
    	{
    		if ( index == 0 )
    		{
    			return y_buffer_;
    		}
    		else if ( index == 1 )
    		{
    			return u_buffer_;
    		}
    		else if ( index == 2 )
    		{
    			return v_buffer_;
    		}
    		else
    		{
    			Log.e(TAG, "I420ExternalRender::getNTPlaneByteBuffer index error:" + index);
    			return null;
    		}
    	}

    	@Override
    	public int getNTPlanePerRowBytes(int index)
    	{
    		if ( index == 0 )
    		{
    			return y_row_bytes_;
    		}
    		else if ( index == 1)
    		{
    			return u_row_bytes_;
    		}
    		else if (index == 2 )
    		{
    			return v_row_bytes_;
    		}
    		else
    		{
    			Log.e(TAG, "I420ExternalRender::getNTPlanePerRowBytes index error:" + index);
    			return 0;
    		}
    	}

    	public void onNTRenderFrame()
    	{
    		if ( y_buffer_ == null )
    			return;
    		
    		if ( u_buffer_ == null )
    			return;
    		
    		if ( v_buffer_ == null )
    			return;
    		
      
    		y_buffer_.rewind();
    		
    		u_buffer_.rewind();
    		
    		v_buffer_.rewind();
    		
    		 // copy buffer
    		
    		// test
    		// byte[] test_buffer = new byte[16];
    		// y_buffer_.get(test_buffer);
    		 
    		// Log.i(TAG, "I420ExternalRender::onNTRenderFrame y data:" + bytesToHexString(test_buffer));
    		 
    		// u_buffer_.get(test_buffer);
    		// Log.i(TAG, "I420ExternalRender::onNTRenderFrame u data:" + bytesToHexString(test_buffer));
    		 
    		// v_buffer_.get(test_buffer);
    		// Log.i(TAG, "I420ExternalRender::onNTRenderFrame v data:" + bytesToHexString(test_buffer));
    	}
    }
    
    
    class EventHande implements SmartEventCallback
    {
    	 @Override
    	 public void onCallback(int code, long param1, long param2, String param3, String param4, Object param5){
             switch (code) {
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STARTED:
                     Log.i(TAG, "开始。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTING:
                     Log.i(TAG, "连接中。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTION_FAILED:
                     Log.i(TAG, "连接失败。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_CONNECTED:
                     Log.i(TAG, "连接成功。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_DISCONNECTED:
                     Log.i(TAG, "连接断开。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_STOP:
                     Log.i(TAG, "关闭。。");
                     break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_RESOLUTION_INFO:
                	 Log.i(TAG, "分辨率信息: width: " + param1 + ", height: " + param2);
                	 break;
                 case EVENTID.EVENT_DANIULIVE_ERC_PLAYER_NO_MEDIADATA_RECEIVED:
                	 Log.i(TAG, "收不到媒体数据,可能是url错误。。");
             }
    	 }
    }
    
    /* Create rendering */
    private boolean CreateView() {
    	
        if(sSurfaceView == null)
        {
        	 /*
             *  useOpenGLES2:
             *  If with true: Check if system supports openGLES, if supported, it will choose openGLES.
             *  If with false: it will set with default surfaceView;	
             */
        	sSurfaceView = NTRenderer.CreateRenderer(this, true);
        }
        
        if(sSurfaceView == null)
        {
        	Log.i(TAG, "Create render failed..");
        	return false;
        }

        return true;
	}
    
	@Override  
    public void onConfigurationChanged(Configuration newConfig) {  
            super.onConfigurationChanged(newConfig);  
            
            Log.i(TAG, "Run into onConfigurationChanged++");
            
            if (null != fFrameLayout)
            {
            	fFrameLayout.removeAllViews();
            	fFrameLayout = null;
            }
            
            if (null != lLayout)
            {
                lLayout.removeAllViews();
                lLayout = null;
            }
            
            if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) 
            {   
            	Log.i(TAG, "onConfigurationChanged, with LANDSCAPE。。");

            	inflateLayout(LinearLayout.HORIZONTAL);
                 
            	currentOrigentation = LANDSCAPE;
            } 
            else
            {  
            	Log.i(TAG, "onConfigurationChanged, with PORTRAIT。。"); 
            	
            	inflateLayout(LinearLayout.VERTICAL);
            	
            	currentOrigentation = PORTRAIT;
            }  
            
            if(!isPlaybackViewStarted)
            	return;
            
            libPlayer.SmartPlayerSetOrientation(playerHandle, currentOrigentation);

            Log.i(TAG, "Run out of onConfigurationChanged--");
    }
    
	@Override
    protected  void onDestroy()
	{
		Log.i(TAG, "Run into activity destory++");   	
    	
		if(playerHandle!=0)
		{
			libPlayer.SmartPlayerClose(playerHandle);	
			playerHandle = 0;
		}
		super.onDestroy();
    	finish();
//    	System.exit(0);
    }
}