YouTube einbetten

  • YouTube einbetten

    Hallo,

    ich würde gerne ein YouTube Video in meine App einbetten.
    Das habe ich wie folgt realisiert, was auch einwandfrei funktioniert:

    HTML-Quellcode

    1. - (void)embedYouTube:(NSString*)url frame:(CGRect)frame {
    2. NSString* embedHTML = @"\
    3. <html><head>\
    4. <style type="text/css">\
    5. body {\
    6. background-color: transparent;\
    7. color: white;\
    8. }\
    9. </style>\
    10. </head><body style=\"margin:0\">\
    11. <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
    12. width=\"%0.0f\" height=\"%0.0f\"></embed>\
    13. </body></html>";
    14. NSString* html = [NSString stringWithFormat:embedHTML, url, frame.size.width, frame.size.height];
    15. if(videoView == nil) {
    16. videoView = [[UIWebView alloc] initWithFrame:frame];
    17. [self.view addSubview:videoView];
    18. }
    19. [videoView loadHTMLString:html baseURL:nil];
    20. }
    Alles anzeigen


    Das Video bzw. die Video-ID würde ich gerne täglich wechseln.
    Ich denke mir das so:
    Video-ID in *.txt auf einem Web-Server, App liest Video-ID aus dieser *.txt.

    Ich kann bereits aus einer *.txt, die in Resources abgelegt ist, lesen.

    Quellcode

    1. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"];
    2. NSString *textFromFile = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];


    Nun die Frage, wie das geht mit einer *.txt von einer URL.

    Grüße

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von AR.DDev ()

  • Im unschönen Fall:

    Quellcode

    1. NSString *string = [NSString stringWithContentOfURL:url]


    im schönen Fall, machste einen NSURLRequest über ne NSURLConnection und erhällst die Daten per Delegat.
    „When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck.“
    – James Whitcomb Riley