2016-11-15 5 views
-1

デバイスからの画像やビデオのスライドショーのようなアプリを実行する必要があります。 私はいくつかのプロジェクトを試みましたが、誰もビデオを表示することはできません。 どうすればいいですか?私が必要とするすべてを繰り返し、表示するために、UIのない​​デバイスからの画像や動画がUIにスティックせずにアプリやアプリリソースに画像や動画を繰り返し表示するには

を立ち往生されますされ、私がしようとしたプロジェクトのいくつかがあります。 https://github.com/daimajia/AndroidImageSlider https://github.com/marvinlabs/android-slideshow-widget

は私があなたに

+2

私たちはあなたのためにあなたの仕事をするためではありません。まず、動画を再生する方法をまず理解してから、アプリでどのように表示するかを心配してください。それはそれほど複雑ではなく、ちょっとしたステップを取るだけです。 –

+0

あなたのUIはあまりにも多くの画像を使用しているためにスタックされています。大きなサイズの画像を使用している場合、10kb以下の画像が必要です。 – Innocent

+0

私はビデオの再生方法を知っています。 しかし、私はどのようにビデオに画像を変更することができますし、逆転 – user2354982

答えて

1

ありがとうございました動画のリストを示す: Activityコード:

public class VideoListActivity extends AppCompatActivity { 

    private ListView lvVideos; 

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

     lvVideos = (ListView)findViewById(R.id.lvVideos); 
     lvVideos.setAdapter(new VideosListAdapter(this)); 

    } 
} 

アダプターコード:

public class VideosListAdapter extends BaseAdapter { 

    private static LayoutInflater inflater = null; 

    private ArrayList<VideoData> listVideoData = new ArrayList<>(); 
    private String[] creationDates = new String[0]; 

    public VideosListAdapter(VideoListActivity videoListActivity) { 
     inflater = (LayoutInflater) videoListActivity 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     // here is a listVideoData and the creationDates initialisation code. 
    } 

    @Override 
    public int getCount() { 
     return listVideoData.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return listVideoData.get(position); 
    } 

    @Override 
    public long getItemId(int position) { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     View vi = convertView; 
     if (vi == null) { 
      vi = inflater.inflate(R.layout.row_video, null); 
     } 
     VideoData videoData = listVideoData.get(position); 
     VideoView videoView = (VideoView)vi.findViewById(R.id.videoView); 
     videoView.setVideoPath(videoData.getVideoFilePath()); 

     TextView tvDate = (TextView) vi.findViewById(R.id.tvDate); 
     tvDate.setText(creationDates[position]); 

     TextView tvInfo = (TextView) vi.findViewById(R.id.tvPuppetInfo); 
     tvInfo.setText("Whatever you want"); 


     // must add this: -otherwise I don't know why, but is not working the click 
     RelativeLayout relativeLayout = (RelativeLayout)videoView.getParent(); 
     relativeLayout.setClickable(true); 
     relativeLayout.setOnClickListener(rlClickListener); 

     return vi; 
    } 


    View.OnClickListener rlClickListener = new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      VideoView videoView = (VideoView)v.findViewById(R.id.videoView); 
       videoView.start(); 

     } 
    }; 
} 

row_video.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:orientation="vertical"> 

    <!-- Yes, it is in pixel, hardcoded, because this is what is requested --> 
    <VideoView 
     android:id="@+id/videoView" 
     android:layout_width="1280px" 
     android:layout_height="720px" 
     android:layout_centerHorizontal="true" /> 


    <TextView 
     android:id="@+id/tvDate" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/videoView" 
     android:layout_below="@+id/videoView" 
     android:layout_marginTop="5dp" 
     android:focusable="false" 
     android:text="25/12/2016 12:59:59" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     /> 


    <TextView 
     android:id="@+id/tvStatus" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/videoView" 
     android:layout_below="@+id/videoView" 
     android:layout_marginTop="5dp" 
     android:drawableRight="@drawable/red_check" 
     android:text="whatever you want" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textStyle="bold" /> 


    <TextView 
     android:id="@+id/tvInfo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/videoView" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="1dp" 
     android:gravity="center" 
     android:layout_toLeftOf="@+id/tvStatus" 
     android:layout_toRightOf="@+id/tvDate" 
     android:focusable="false" 
     android:text="" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 


</RelativeLayout> 

のコード部分私はupvoteそれは価値願っています! (クリック)

関連する問題