當前位置:首頁 » 安卓系統 » android視頻播放器代碼

android視頻播放器代碼

發布時間: 2022-11-03 22:03:49

A. android 如何實現圖片視頻混合播放啊

直接上代碼:

布局文件就是兩個全屏的videoview和imageview重疊

<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/pictureView"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>

<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


</LinearLayout>

java部分:

/*
視頻圖片混合展示demo
*/
packagecom.example.administrator.hunbo;

importandroid.content.Context;
importandroid.media.MediaPlayer;
importandroid.net.Uri;
importandroid.os.Handler;
importandroid.os.storage.StorageManager;
importandroid.support.v7.app.AppCompatActivity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.widget.ImageView;
importandroid.widget.Toast;
importandroid.widget.VideoView;
importjava.io.File;
importjava.lang.reflect.InvocationTargetException;
importjava.lang.reflect.Method;
importjava.util.ArrayList;

{

privateVideoViewvideoView;
privateImageViewpictureView;
booleanisPlaying=false;
privateArrayListarrayList=newArrayList<String>();

@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().hide();//隱藏actionBar
//初始化控制項
videoView=findViewById(R.id.videoView);
pictureView=findViewById(R.id.pictureView);
//最開始兩個view都是隱藏的
videoView.setVisibility(View.GONE);
pictureView.setVisibility(View.GONE);
//檢測SD卡是否存在
String[]result=null;
StorageManagerstorageManager=(StorageManager)getSystemService(Context.STORAGE_SERVICE);
try{
Methodmethod=StorageManager.class.getMethod("getVolumePaths");
method.setAccessible(true);
try{
result=(String[])method.invoke(storageManager);
}catch(InvocationTargetExceptione){
e.printStackTrace();
}
if(result.length>1){
//Toast.makeText(this,"檢測到U盤",Toast.LENGTH_SHORT).show();
AllFilesPath("/mnt/usb/");
playList();
}else{
Toast.makeText(this,"未檢測到U盤,請在開機前插入U盤,或者重新啟動此應用",Toast.LENGTH_SHORT).show();
Handlerhandler=newHandler();
handler.postDelayed(newRunnable(){
@Override
publicvoidrun(){
finish();
}
},2500);
}
}catch(Exceptione){
e.printStackTrace();
}
}
//獲取所有圖片視頻的絕對路徑到arraylist
privateArrayListAllFilesPath(Stringpath){
Filefile=newFile(path);
File[]files=file.listFiles();
for(Filef:files){
if(f.getName().endsWith("jpg")||f.getName().endsWith("jpeg")||f.getName().endsWith("mp4")
||f.getName().endsWith("avi")||f.getName().endsWith("mkv")||f.getName().endsWith("rmvb")
||f.getName().endsWith("flv")){
System.out.println("------------獲取到了一個可用路徑:"+f.getAbsolutePath());
arrayList.add(f.getAbsolutePath());//添加到arralist
}elseif(f.isDirectory()){
AllFilesPath(f.getAbsolutePath());
}
}
returnarrayList;
}
//依次混合播放arralist里的圖片或視頻

publicintlistNum;
privatevoidplayList(){
if(listNum>=arrayList.size()){
finish();
//listNum=0;
}else{
System.out.println("---------------------------收入路徑---------------------------");
System.out.println("isplaying="+isPlaying);
finalFilef=newFile(arrayList.get(listNum).toString());
if(f.getName().endsWith("jpg")||f.getName().endsWith("jpeg")||f.getName().endsWith("png")){
System.out.println("---------------------------添加了一張圖片:"+f.getAbsolutePath());
pictureView.setVisibility(View.VISIBLE);
pictureView.setImageURI(Uri.fromFile(f));
Handlerhandler=newHandler();
handler.postDelayed(newRunnable(){
@Override
publicvoidrun(){
System.out.println("---------------------------播完了一張位於"+f.getAbsolutePath()+"的圖片》》》》》》》》》》》》》》》》》");
pictureView.setVisibility(View.GONE);
listNum++;
playList();
}
},2000);//2秒後結束當前圖片
}elseif(f.getName().endsWith("mp4")||f.getName().endsWith("avi")||f.getName().endsWith("mkv")
||f.getName().endsWith("rmvb")||f.getName().endsWith("flv")){
System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~添加了一個視頻"+f.getAbsolutePath());
videoView.setVideoPath(f.getAbsolutePath());
videoView.setVisibility(View.VISIBLE);//播放之前顯示videoView
videoView.start();
videoView.setOnCompletionListener(newMediaPlayer.OnCompletionListener(){
@Override
publicvoidonCompletion(MediaPlayermp){
System.out.println("---------------------------播完了一個位於"+f.getAbsolutePath()+"的視頻《《《《《《《《《《《《《《《《《《");
videoView.setVisibility(View.GONE);//視頻播放完畢後隱藏videoView
listNum++;
playList();
}
});
}
}
}

B. 基於Android開發一款視頻播放器

自己開發播放器,是不是太難了。你可以使用android自帶的mediaplayer。

C. android開發中實現點擊按鈕打開本地視頻播放器 求解。

Intent intent = new Intent(android.intent.action.VIEW);
intent.setType("video/*");
startActivity(intent);

D. Android項目視頻播放器例子

InputStream is = getResources().openRawResource(R.id.filename);
調用url的地方也要改下 沒看到代碼 ,你自己改吧,應為用到url的地方是通過訪問網路得到的InputStream,這里已經得到了,很好改的,

希望能幫到你!

E. 急求一個測試​Android的手機視頻播放系統在線播放功能的URL地址

知道優酷m3u8的可以拼接了將傳到播放器里inten的data 拼接一下成為可以播的m3u8設置到setdatasource裡面,土豆的也可以但是要麻煩些要獲取縮略圖的地址再轉成m3u8的。還有更好的方法嘛,直接調javascript
Android平台下SeeJoPlayer視頻播放器(功能介紹及源碼解析,附源碼)
http://www.blogjava.net/zh-weir/archive/2010/01/24/310617.html

F. 用Android studio開發一個手機視頻播放器應用,求幫忙,兄弟們,謝謝

手機視頻播放的簡單實現代碼已經上傳,電腦打開本界面可下載附件, 但是這個是用eclipse開發的, 可以選擇視頻音樂進行播放

G. android 中播放視頻時總報出 視頻無法播放的錯誤,程序中的異常是 ActivityNotFoundException。

1、是你的視頻播放器的代碼問題。
2、或者這個視頻播放器對Android系統的版本要求,高於你當前的版本號。

H. Android開發一個視頻播放器,播放列表中有視頻縮略圖,文件名,路徑,時間,大小,怎麼讓他們放在一個

這個問題本身不難,你貼一堆代碼這么亂怎麼看?

要實現這樣的功能呢,建議你自定義一個adapter繼承自BaseAdapter,然後在getView方法里,
載入一個item布局,這個item布局可以包含imageView,自己寫一個就好。
自定義的adapter可以設置數據源,構造方法中可以加上一個list map數據源,
獲取到數據源之後傳進來,根據position設置好對應數據就好了。

熱點內容
存儲標准性 發布:2024-05-03 13:37:07 瀏覽:416
液鹼存儲 發布:2024-05-03 13:21:13 瀏覽:156
linux如何改配置文件 發布:2024-05-03 13:00:54 瀏覽:31
哪個安卓模擬器老爺機帶得動 發布:2024-05-03 13:00:49 瀏覽:576
編程與實戰 發布:2024-05-03 12:54:30 瀏覽:38
電腦開機有密碼rpc伺服器不可用 發布:2024-05-03 12:40:54 瀏覽:471
硬體的演算法 發布:2024-05-03 12:34:28 瀏覽:388
支付密碼為什麼就六位 發布:2024-05-03 12:29:17 瀏覽:920
腳本找書 發布:2024-05-03 12:02:17 瀏覽:493
境外伺服器租用怎麼辦 發布:2024-05-03 11:45:34 瀏覽:944