Guten Abend,
ich bin seit kurzen unter die App Entwickler gegangen, da mich ein Freund gefragt hab, ob ich für ihn nicht eine App programmieren könnte.
Ich muss aber dazu sagen, dass ich nicht der erfahrenste Programmierer bin. Ein bisschen C, C++, hier und da zwei Wörter Java und Visual Basic. Mit Objective C hatte ich allerdings sonst noch keinen Kontakt.
Beschreibung des Problems:
In der App gibt es einen Tab in dem mehrere Videos abgespielt werden sollen. Dabei soll das Programm eine Textdatei auslesen in der steht wie viele Videos zurzeit verfügbar sind und dem entsprechend viele Mediaplayer inkl. Textfeld erzeugen. Das wollte ich durch eine for Schleife lösen. Als Mediaplayer benutze ich das MediaPlayer.framework. Allerdings scheint es so als wenn ich damit nur jeweils ein Mediaplayer pro View haben kann. Solange ich nur einen Mediaplayer erstelle kann ich mir auf diesem das Video problemlos anschauen. Sobald allerdings ein zweiter Mediaplayer hinzu kommt läuft nur noch der zweite bzw der zuletzt erstellte.
Im Anhang hab ich die .m und die .h Datei ich hab in die .m Datei an den entsprechenden Stellen mal etwas kommentiert wo ich Probleme hab. Ich hoffe ihr könnt mir helfen.
Schon mal danke fürs durchlesen
Meine .m Datei:
#import "PlayerboyVideoViewController.h"
@interface PlayerboyVideoViewController ()
@end
@implementation PlayerboyVideoViewController
@synthesize moviePlayer1;
@synthesize moviePlayer2;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Set the contentSize of the ScrollView
self.scrollView.contentSize = CGSizeMake(320,680);
//First Mediaplayer
NSURL *url1 = [[NSURL alloc]initWithString:@"http://TestURL.de/Video_1.mov"]; //die URL hab ich ausgetauscht
moviePlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:url1];
[moviePlayer1.view setFrame:CGRectMake(0,10,320,180)];
[self.scrollView addSubview:moviePlayer1.view];
moviePlayer1.fullscreen = NO;
moviePlayer1.allowsAirPlay = YES;
moviePlayer1.shouldAutoplay = NO;
moviePlayer1.controlStyle = MPMovieControlStyleDefault;
//second Mediaplayer
NSURL *url2 = [[NSURL alloc]initWithString:@"http://TestURL.de/Video_2.mov"]; //die URL hab ich ausgetauscht
moviePlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:url2];
[moviePlayer2.view setFrame:CGRectMake(0,500,320,180)];
[self.scrollView addSubview:moviePlayer2.view];
moviePlayer2.fullscreen = NO;
moviePlayer2.allowsAirPlay = YES;
moviePlayer2.shouldAutoplay = NO;
moviePlayer2.controlStyle = MPMovieControlStyleDefault;
//Später sollen mehrere Mediaplayer je nach Anzahl an Videos auf dem Server erstellt werden
//Es stellt sich mir nur die Frage wie erstens die Zeile
@property(nonatomic,strong) MP…Controller * mediaPlayer;
dann aussehen muss… ist das auch in der Header Datei mit einer for schleife zu lösen?
//und zweitens ob ich hier mit dem Array richtig um gegangen bin?! Das ist ja doch etwas anders als in C++ oder Java
/*int a = 2;
NSMutableArray *moviePlayerArray;
for(int i = 1; i <= a; i++) {
// create a url for one of the videos
NSString *urlStr = [[NSString alloc] initWithFormat:@"http://TestURL.de/Video_%d.mov", i];
NSURL *url = [[NSURL alloc]initWithString:urlStr];
//Create a MediaPlayer
[moviePlayerArray addObject:[[MPMoviePlayerController alloc]initWithContentURL:url]];
int pos = -170 + (i * 180);
int h = i - 1;
[((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).view setFrame:CGRectMake(0,pos,320,180)];
[self.view addSubview:((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).view];
//Some additional customizations
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).fullscreen = YES;
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).allowsAirPlay = YES;
//((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).shouldAutoplay = YES;
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).controlStyle = MPMovieControlStyleDefault;
}*/
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Meine .h Datei:
#import <UIKit/UIKit.h>
#import "MediaPlayer/MediaPlayer.h"
@interface PlayerboyVideoViewController : UIViewController
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer1;
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer2;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end
ich bin seit kurzen unter die App Entwickler gegangen, da mich ein Freund gefragt hab, ob ich für ihn nicht eine App programmieren könnte.
Ich muss aber dazu sagen, dass ich nicht der erfahrenste Programmierer bin. Ein bisschen C, C++, hier und da zwei Wörter Java und Visual Basic. Mit Objective C hatte ich allerdings sonst noch keinen Kontakt.
Beschreibung des Problems:
In der App gibt es einen Tab in dem mehrere Videos abgespielt werden sollen. Dabei soll das Programm eine Textdatei auslesen in der steht wie viele Videos zurzeit verfügbar sind und dem entsprechend viele Mediaplayer inkl. Textfeld erzeugen. Das wollte ich durch eine for Schleife lösen. Als Mediaplayer benutze ich das MediaPlayer.framework. Allerdings scheint es so als wenn ich damit nur jeweils ein Mediaplayer pro View haben kann. Solange ich nur einen Mediaplayer erstelle kann ich mir auf diesem das Video problemlos anschauen. Sobald allerdings ein zweiter Mediaplayer hinzu kommt läuft nur noch der zweite bzw der zuletzt erstellte.
Im Anhang hab ich die .m und die .h Datei ich hab in die .m Datei an den entsprechenden Stellen mal etwas kommentiert wo ich Probleme hab. Ich hoffe ihr könnt mir helfen.
Schon mal danke fürs durchlesen
Meine .m Datei:
#import "PlayerboyVideoViewController.h"
@interface PlayerboyVideoViewController ()
@end
@implementation PlayerboyVideoViewController
@synthesize moviePlayer1;
@synthesize moviePlayer2;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Set the contentSize of the ScrollView
self.scrollView.contentSize = CGSizeMake(320,680);
//First Mediaplayer
NSURL *url1 = [[NSURL alloc]initWithString:@"http://TestURL.de/Video_1.mov"]; //die URL hab ich ausgetauscht
moviePlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:url1];
[moviePlayer1.view setFrame:CGRectMake(0,10,320,180)];
[self.scrollView addSubview:moviePlayer1.view];
moviePlayer1.fullscreen = NO;
moviePlayer1.allowsAirPlay = YES;
moviePlayer1.shouldAutoplay = NO;
moviePlayer1.controlStyle = MPMovieControlStyleDefault;
//second Mediaplayer
NSURL *url2 = [[NSURL alloc]initWithString:@"http://TestURL.de/Video_2.mov"]; //die URL hab ich ausgetauscht
moviePlayer2 = [[MPMoviePlayerController alloc] initWithContentURL:url2];
[moviePlayer2.view setFrame:CGRectMake(0,500,320,180)];
[self.scrollView addSubview:moviePlayer2.view];
moviePlayer2.fullscreen = NO;
moviePlayer2.allowsAirPlay = YES;
moviePlayer2.shouldAutoplay = NO;
moviePlayer2.controlStyle = MPMovieControlStyleDefault;
//Später sollen mehrere Mediaplayer je nach Anzahl an Videos auf dem Server erstellt werden
//Es stellt sich mir nur die Frage wie erstens die Zeile
@property(nonatomic,strong) MP…Controller * mediaPlayer;
dann aussehen muss… ist das auch in der Header Datei mit einer for schleife zu lösen?
//und zweitens ob ich hier mit dem Array richtig um gegangen bin?! Das ist ja doch etwas anders als in C++ oder Java
/*int a = 2;
NSMutableArray *moviePlayerArray;
for(int i = 1; i <= a; i++) {
// create a url for one of the videos
NSString *urlStr = [[NSString alloc] initWithFormat:@"http://TestURL.de/Video_%d.mov", i];
NSURL *url = [[NSURL alloc]initWithString:urlStr];
//Create a MediaPlayer
[moviePlayerArray addObject:[[MPMoviePlayerController alloc]initWithContentURL:url]];
int pos = -170 + (i * 180);
int h = i - 1;
[((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).view setFrame:CGRectMake(0,pos,320,180)];
[self.view addSubview:((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).view];
//Some additional customizations
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).fullscreen = YES;
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).allowsAirPlay = YES;
//((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).shouldAutoplay = YES;
((MPMoviePlayerController *) [moviePlayerArray objectAtIndex: h]).controlStyle = MPMovieControlStyleDefault;
}*/
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Meine .h Datei:
#import <UIKit/UIKit.h>
#import "MediaPlayer/MediaPlayer.h"
@interface PlayerboyVideoViewController : UIViewController
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer1;
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer2;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@end
Think positive, flaps negative!