基於VLC的視頻播放器,VLC視頻播放器

來源:互聯網
上載者:User

基於VLC的視頻播放器,VLC視頻播放器

  最近在研究視頻播放的功能,之前是使用VideoView。在網上看了一下,感覺不是很好,支援的格式比較少,現在網路視頻的格式各種各樣,感覺用VideoView播放起來局限性很大。

  找到了一個比較合適的播放器,Github地址為https://github.com/xiaomo/AndroidPlayerLibrary 。這個播放器是基於vlc這個軟體,在將我們的demo匯入到Eclipse中之後,可以發現,這樣一個libvlc檔案夾。

  在Media這個類中我們可以發現,這些是支援的格式還是比較多的。

String[] video_extensions = {                ".3g2", ".3gp", ".3gp2", ".3gpp", ".amv", ".asf", ".avi", ".divx", ".drc", ".dv",                ".f4v", ".flv", ".gvi", ".gxf", ".ismv", ".iso", ".m1v", ".m2v", ".m2t", ".m2ts",                ".m4v", ".mkv", ".mov", ".mp2", ".mp2v", ".mp4", ".mp4v", ".mpe", ".mpeg",                ".mpeg1", ".mpeg2", ".mpeg4", ".mpg", ".mpv2", ".mts", ".mtv", ".mxf", ".mxg",                ".nsv", ".nut", ".nuv", ".ogm", ".ogv", ".ogx", ".ps", ".rec", ".rm", ".rmvb",                ".tod", ".ts", ".tts", ".vob", ".vro", ".webm", ".wm", ".wmv", ".wtv", ".xesc" };String[] audio_extensions = {                ".3ga", ".a52", ".aac", ".ac3", ".adt", ".adts", ".aif", ".aifc", ".aiff", ".amr",                ".aob", ".ape", ".awb", ".caf", ".dts", ".flac", ".it", ".m4a", ".m4b", ".m4p",                ".mid", ".mka", ".mlp", ".mod", ".mpa", ".mp1", ".mp2", ".mp3", ".mpc", ".mpga",                ".oga", ".ogg", ".oma", ".opus", ".ra", ".ram", ".rmi", ".s3m", ".spx", ".tta",                ".voc", ".vqf", ".w64", ".wav", ".wma", ".wv", ".xa", ".xm" };

  在這個例子中它自己寫了一個PlayerActivity和PlayerView,在PlayerView中實現了libvlc中的IVideoPlayer介面

 

  在PlayerActivity中實現PlayerView類,從而進行介面和流程的控制。

protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        mUrl = getIntent().getStringExtra("url");        if (TextUtils.isEmpty(mUrl)) {            Toast.makeText(this, "error:no url in intent!", Toast.LENGTH_SHORT).show();            return;        }        requestWindowFeature(Window.FEATURE_NO_TITLE);        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);        setContentView(R.layout.activity_player);        mHandler = new Handler(this);        tvTitle = (TextView) findViewById(R.id.tv_title);        tvTime = (TextView) findViewById(R.id.tv_time);        tvLength = (TextView) findViewById(R.id.tv_length);        sbVideo = (SeekBar) findViewById(R.id.sb_video);        sbVideo.setOnSeekBarChangeListener(this);        ibLock = (ImageButton) findViewById(R.id.ib_lock);        ibLock.setOnClickListener(this);        ibBackward = (ImageButton) findViewById(R.id.ib_backward);        ibBackward.setOnClickListener(this);        ibPlay = (ImageButton) findViewById(R.id.ib_play);        ibPlay.setOnClickListener(this);        ibFarward = (ImageButton) findViewById(R.id.ib_forward);        ibFarward.setOnClickListener(this);        ibSize = (ImageButton) findViewById(R.id.ib_size);        ibSize.setOnClickListener(this);        llOverlay = findViewById(R.id.ll_overlay);        rlOverlayTitle = findViewById(R.id.rl_title);        rlLoading = findViewById(R.id.rl_loading);        tvBuffer = (TextView) findViewById(R.id.tv_buffer);        //使用步驟        //第一步 :通過findViewById或者new PlayerView()得到mPlayerView對象        //mPlayerView= new PlayerView(PlayerActivity.this);        mPlayerView = (PlayerView) findViewById(R.id.pv_video);        //第二步:設定參數,毫秒為單位        mPlayerView.setNetWorkCache(20000);        //第三步:初始化播放器        mPlayerView.initPlayer(mUrl);        //第四步:設定事件監聽,監聽緩衝進度等        mPlayerView.setOnChangeListener(this);        //第五步:開始播放        mPlayerView.start();        //init view        tvTitle.setText(mUrl);        showLoading();        hideOverlay();    }

  關於如何使用這個類庫

  庫兩種使用方式:

第一種,直接new一個PlayerView或者在布局檔案的xml裡面嵌入view。

第二種,跳轉到一個寫好的播放頁面PlayerActivity (本地檔案參數格式:file:///sacard/test.rmvb。)

  這裡我選擇了第二種方法

startActivity(new Intent(this, PlayerActivity.class).putExtra("url", items.get(position)));

  通過一個挑選清單的形式,點擊每一項,傳遞一個url到PlayerActivity

  挑選清單中的1.2JDK下載.mp4

  橫豎屏的切換也是沒有問題的。 

  如果大家有好的播放器,也歡迎大家和我交流。

 

作者:傑瑞教育
出處:http://www.cnblogs.com/jerehedu/ 
本文著作權歸煙台傑瑞教育科技有限公司和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文串連,否則保留追究法律責任的權利。 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.