1

VIDEO ACTIVITY

with the code that you gave me to be included in videoactivity me an error on the url at the line private String VIDEO = url; tells me that url can not be resolved to a variable

public class VideoActivity extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {

static private final String DEVELOPER_KEY = "AIzaSyBR-QH8hCO8U_WE_sIPGhEQIGmBEYCi7pQ";

private String VIDEO = url;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.videoactivity);
          YouTubePlayerView youTubeView = (YouTubePlayerView)
                  findViewById(R.id.youtube_video);
       youTubeView.initialize(DEVELOPER_KEY, this);
       Bundle bundle = getIntent().getExtras();
       final String url = bundle.getString("url1");

   }


   public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
            Toast.makeText(this, "Oh no! Errore di Connessione, provi a rientrare"+error.toString(),
Toast.LENGTH_LONG).show();
   }
   @Override
   public void onInitializationSuccess(Provider provider, YouTubePlayer player,
boolean wasRestored) {
          player.loadVideo(VIDEO);
   }

}

john
  • 97
  • 1
  • 1
  • 9

1 Answers1

1

Use:

Intent video = new Intent(EpisodiActivity.this,VideoActivity.class);
video.putExtra("url", "value");
startActivity(video);

so likewise in you class:

mylist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
        Intent video = new Intent(EpisodiActivity.this,VideoActivity.class);
        String urlFromListView=(String)arg0.getItemAtPosition(position);
        video.putExtra("url",urlFromListView);
        startActivity(video);
    }
});

To Retrieve it in VideoActivity:

inside onCreate(Bundle savedInstanceState) after setContentView(R.layout.videoactivity);

Bundle bundle = getIntent().getExtras();
final String url = bundle.getString("url");
Sagar Pilkhwal
  • 5,825
  • 2
  • 24
  • 76
  • and the url where should I put them? – john Sep 07 '14 at 20:16
  • url of youtube video – john Sep 07 '14 at 20:20
  • so u have a list of youtube video `url`, when you click on any list item, see my answer it will start `VideoActivity` answer send the `url` and in `VideoActivity` use `Bundle bundle = getIntent().getExtras(); final String key = bundle.getString("key");` – Sagar Pilkhwal Sep 07 '14 at 20:24
  • sorry but you have not answered my earlier question, where do I insert the url? – john Sep 07 '14 at 20:28
  • in `video.putExtra("url",urlFromListView);` `urlFromListView` is your url – Sagar Pilkhwal Sep 07 '14 at 20:30
  • excuse me but I'm trying, but is full of mistakes, could you show me a example with 2 url in case please? – john Sep 07 '14 at 20:36
  • no are more than 2, is a random number :) – john Sep 07 '14 at 20:43
  • `video.putExtra("url1",urlFromListView);` and `video.putExtra("url2",urlFromListView);` and in `VideoActvity` `Bundle bundle = getIntent().getExtras();` `final String url1 = bundle.getString("url1");` and `final String url2 = bundle.getString("url2");` – Sagar Pilkhwal Sep 07 '14 at 20:43
  • you can directly pass the string array object and then in `VideoActivity` `bundle.getStringArray("url")` – Sagar Pilkhwal Sep 07 '14 at 20:46
  • ok let's see if I understand if for example the url are 10 I have to do ten of these lines video.putExtra ("url1" urlFromListView); , Changing only the number of the url? and the same thing I have to do it well in videoactivity? – john Sep 07 '14 at 20:46
  • you can pass `url[]` remember `"urlArray"` this is just a name you give its not a keyword `video.putExtra("urlArray",urlArray);` – Sagar Pilkhwal Sep 07 '14 at 20:50
  • sorry I do not understand a thing but I have to put the url in place of url2 or urlFromListView? – john Sep 07 '14 at 20:50
  • sorry I'm doing a bit of confusion you show me an example of code please, so I can vote you the answer :) – john Sep 07 '14 at 20:52
  • try [this link](http://www.androidbegin.com/tutorial/android-custom-listview-texts-tutorial/), its very simple and self explanatory. – Sagar Pilkhwal Sep 08 '14 at 06:26
  • ok I miss only one thing to understand now, in videoactivity if I write the code that you gave me tells me that the local variable url is not used. what do I do? but here, VIDEO private String = ??? I have to put this "url" or without quotes – john Sep 08 '14 at 09:32
  • use `private String VIDEO = "";` & `VIDEO = bundle.getString("url1");` – Sagar Pilkhwal Sep 08 '14 at 09:52
  • Comments are not for extended discussion; this conversation has been [moved to chat](http://chat.stackoverflow.com/rooms/60814/discussion-on-answer-by-sagar-pilkhwal-how-do-i-pass-data-between-two-activities). – Taryn Sep 08 '14 at 10:37