Aller au contenu

Problème d'affichage android


nathalie85

Recommended Posts

Bonjour à tous,

Voila je développe une application composé d'un visuel, des questions sur le visuel, et en cliquant sur les questions on a les réponses dans une vue avec texte, image et vidéo.

Le texte et l'image s'affiche sans problème, par contre la vidéo ne s'affiche pas.

Pour cela j'utilise VideoView, je procède de la même manière que pour l'ImageView qui fonctionne, mais ça ne marche pas.

Et je n'ai pas d'erreurs dans le logcat.

Voila si quelqu'un peut jeter un oeil et me dire ce qui ne va pas dans mon code.

Merci d'avance.

Voila mon code:

main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<android.opengl.GLSurfaceView
android:id="@+id/glSurface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="300dp"
android:layout_height="500dp"
android:layout_marginBottom="4dp" >
</ListView>
<RelativeLayout
android:id="@+id/RelativeLayout2"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginBottom="2dp"
android:layout_marginRight="2dp"
android:layout_marginTop="4dp "
android:keepScreenOn="true"
android:visibility="visible" >
</RelativeLayout>
</LinearLayout>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView1"
android:layout_width="960dp"
android:layout_height="700dp"
android:background="#ffffff">
<LinearLayout
android:id="@+id/LinearLayout2"
android:layout_width="950dp"
android:layout_height="680dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:background="#ffffff"
android:orientation="vertical" android:isScrollContainer="true" android:scrollbarAlwaysDrawVerticalTrack="true" android:scrollbars="vertical">
<RelativeLayout
android:id="@+id/buttonParentLayout"
android:layout_width="match_parent"
android:layout_height="31dp" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Fermer" android:layout_alignParentRight="true"/>
</RelativeLayout>

<ImageView
android:id="@+id/imageviewTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
</RelativeLayout>

Et voila mon Main.java

public class Main extends Activity{
GLSurfaceView surfaceView;
static Model model = null;
InputStream is=null;
GestureDetector aGestureDetector;
GestureDetector aGestureDetector3D;
GestureDetector aNavigatorGestureListener;
ImageView imgView=null;
ImageView recTransparent=null;
MyGLRenderer glRenderer=null;
Renderer3D glRenderer3d=null;
float xFactor;
private ListView lv=null;
View inflatedView;
ScaleGestureDetector mScaleDetector=null;
Context context = null;
WebView webView =null;
NavigatorView aNavigator=null;
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
ArrayAdapter<Information> lvAdapter;
PageWeb pageWeb;
String baseUrl;
private ArrayList<Information> selectedQuestions;
ZoneView zoneView;
LinearLayout LinearLayout1;
MediaPlayer mediaPlayer;
MediasView mediaView;
LinearLayout mediasLayout;
RelativeLayout buttonParentLayout;
Button btnFermer;
VideoView myVideoView;
SurfaceView surfaceView1;
SurfaceHolder surfaceHolder;
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);	
 this.requestWindowFeature(window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
 setContentView(R.layout.main);
 context = this.getBaseContext();		

 Log.d("DataDirectory",Environment.getDataDirectory().toString());
baseUrl =Environment.getExternalStorageDirectory()+"/Projet";
final String rootPath1= Environment.getExternalStorageDirectory()+"/Projet";
mediasLayout=(LinearLayout) findViewById(R.id.LinearLayout2);
mediasLayout.setVisibility(View.GONE);

final ScrollView ScrollView1 = (ScrollView) findViewById(R.id.ScrollView1);
ScrollView1.setVisibility(View.GONE);
buttonParentLayout = (RelativeLayout) findViewById(R.id.buttonParentLayout);
btnFermer = (Button) findViewById(R.id.button1);
btnFermer.setOnTouchListener(new OnTouchListener() {
public boolean onTouch(View arg0, MotionEvent arg1) {
ScrollView1.setVisibility(View.GONE);
return true;
}
 });

 surfaceView = (GLSurfaceView) this.findViewById(R.id.glSurface);
 lv = (ListView) this.findViewById(R.id.listView1);
 lvAdapter = new ArrayAdapter<Information>(this,android.R.layout.simple_list_item_1,model.getQuestions());
 lv.setAdapter(lvAdapter);
 lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
 public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
	 Object o = lv.getItemAtPosition(position);
	 Information article =(Information) lv.getItemAtPosition(position);
	 TextView questionView = new TextView(context);
	 questionView.setText(article.toString());

	 TextView reponseView = new TextView(context);
	 reponseView.setText(article.getINFORMATION());

	 ArrayList<ImageView> imageViews = new ArrayList<ImageView>();
	 ArrayList<VideoView> videoViews = new ArrayList<VideoView>();

	 int nbrImg = article.getMEDIAS().size();
	 TextView nbrMedias = new TextView(context);
	 nbrMedias.setText(""+nbrImg);
	 int nbrimg =0;
	 int nbrvideo =0;

	 for (int i=0;i<article.getMEDIAS().size();i++){
	 Media media = article.getMEDIAS().get(i);
	 if (media.getMediaType()=="IMAGE") {
	 nbrimg++;

	 String imgPath = media.getUri();
 String strTab[]=imgPath.split("/");

 String newImgPath = rootPath1 + imgPath + "/"+strTab[3];
 FileInputStream in;
		 BufferedInputStream buf;
		 Log.d("newImgPath 2 : ",newImgPath);
		 ImageView image = new ImageView(context);
		 try {
		 in = new FileInputStream(newImgPath);
			 buf = new BufferedInputStream(in);
			 Bitmap bMap = BitmapFactory.decodeStream(buf);
			 image.setImageBitmap(bMap);

		 imageViews.add(image);
			 if (in != null) {
		 in.close();
			 }
			 if (buf != null) {
		 buf.close();
			 }
		 } catch (Exception e) {
			 Log.e("Error reading file1", e.toString());
		 }

	 }

[b]// code pour la vidéo qui n'affiche rien[/b]

 if (media.getMediaType()=="VIDEO") {
	 nbrvideo++;
	 String vidPath = media.getUri();
 String strTab[]=vidPath.split("/");	
 String newVidPath = rootPath1 + vidPath + "/"+strTab[3];	
		 Log.d("VideoImgPath : ",newVidPath);

		 videoView = new VideoView(context);

		 MediaController mediaController = new MediaController(context);
				 videoView.setMediaController(mediaController);
				 try {

			 videoView.setVideoURI(Uri.parse(newVidPath));
			 Log.d("VideoImgPath URI : ",""+Uri.parse(newVidPath));
videoViews.add(videoView);
				 }
				 catch (Exception e) {

				 }

	 }
[b]// code pour la vidéo qui n'affiche rien[/b]

	 mediasLayout.removeAllViews();
	 mediasLayout.removeView(questionView);

	 mediasLayout.addView(buttonParentLayout);
	 mediasLayout.addView(questionView);
	 mediasLayout.addView(reponseView);

	 for(int i=0;i<imageViews.size();i++) {
	 ImageView imgView = imageViews.get(i);
	 mediasLayout.addView(imgView);
	 }


	 for(int i=0;i<videoViews.size();i++) {
	 VideoView videoView=videoViews.get(i);
	 mediasLayout.addView(videoView);
	 //videoView.start();
	 Log.d("VideoViews ","videoViews : "+videoViews.size());
	 }



mediasLayout.setVisibility(View.VISIBLE);
ScrollView1.setVisibility(View.VISIBLE);
 }
 });

 glRenderer = new MyGLRenderer(this,model);
 surfaceView.setRenderer(glRenderer);
 aGestureDetector = new GestureDetector(this, new glSurfaceListener(context,model, lv,lvAdapter,webView,aNavigator));
 mScaleDetector = new ScaleGestureDetector(this, new glSurfaceListener(context,model,lv,lvAdapter,webView,aNavigator));

}

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.

×
×
  • Créer...