Skip to content

Commit

Permalink
Changed the way a video is opened and added the check for mobile netw…
Browse files Browse the repository at this point in the history
…orks
  • Loading branch information
below committed Oct 18, 2009
1 parent 4c938ee commit 4f128a0
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 81 deletions.
4 changes: 4 additions & 0 deletions Apfeltalk Magazin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CB9E94841044929D00768B8B /* libsqlite3.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CB9E94831044929D00768B8B /* libsqlite3.dylib */; };
CBA438FA105836D9002B2077 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = CBA438F9105836D9002B2077 /* libxml2.dylib */; };
CBAE2D8110643DE600160997 /* DetailBody.png in Resources */ = {isa = PBXBuildFile; fileRef = CBAE2D8010643DE600160997 /* DetailBody.png */; };
CBC26121108B9DC500E5F36B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CBC26120108B9DC500E5F36B /* SystemConfiguration.framework */; };
CBC2B8D91068104200040255 /* ATMXMLUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = CBC2B8D81068104200040255 /* ATMXMLUtilities.m */; };
F6222F011041D90D00FC030D /* rss.png in Resources */ = {isa = PBXBuildFile; fileRef = F6222F001041D90D00FC030D /* rss.png */; };
F62230401043488D00FC030D /* MediaPlayer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F622303F1043488D00FC030D /* MediaPlayer.framework */; };
Expand Down Expand Up @@ -119,6 +120,7 @@
CBA438EC1058361C002B2077 /* UIScrollViewPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIScrollViewPrivate.h; sourceTree = "<group>"; };
CBA438F9105836D9002B2077 /* libxml2.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libxml2.dylib; path = usr/lib/libxml2.dylib; sourceTree = SDKROOT; };
CBAE2D8010643DE600160997 /* DetailBody.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = DetailBody.png; sourceTree = "<group>"; };
CBC26120108B9DC500E5F36B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
CBC2B8D71068104200040255 /* ATMXMLUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ATMXMLUtilities.h; sourceTree = "<group>"; };
CBC2B8D81068104200040255 /* ATMXMLUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ATMXMLUtilities.m; sourceTree = "<group>"; };
F6222F001041D90D00FC030D /* rss.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = rss.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -162,6 +164,7 @@
22250A7210510E5E008B2EEC /* MessageUI.framework in Frameworks */,
CBA438FA105836D9002B2077 /* libxml2.dylib in Frameworks */,
22ACCBD51062BAB700EC4E5A /* AudioToolbox.framework in Frameworks */,
CBC26121108B9DC500E5F36B /* SystemConfiguration.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -220,6 +223,7 @@
19C28FACFE9D520D11CA2CBB /* Products */,
22D4A69E105001D500BC3317 /* COPYING */,
5A6749EB105D5971006135C2 /* Appstore.rtf */,
CBC26120108B9DC500E5F36B /* SystemConfiguration.framework */,
);
name = "Apfeltalk Magazin";
sourceTree = "<group>";
Expand Down
6 changes: 3 additions & 3 deletions Classes/DetailLiveticker.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ - (void)viewDidLoad
[(UIScrollView *)[webview.subviews objectAtIndex:0] setAllowsRubberBanding:NO];
}


- (UIImage *) thumbimage {
return [UIImage imageNamed:@"TickerThumbnail.png"];
}

- (NSString *)htmlString
{
thumbnail.image = [UIImage imageNamed:@"TickerThumbnail.png"];

return [NSString stringWithFormat:@"<div style=\"%@\">%@</div>", [self cssStyleString], [self scaledHtmlStringFromHtmlString:[[self story] summary]]];
}

Expand Down
1 change: 1 addition & 0 deletions Classes/DetailPodcast.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#import <MediaPlayer/MediaPlayer.h>

@interface DetailPodcast : DetailViewController <UIWebViewDelegate> {
MPMoviePlayerController* theMovie;
}

@end
68 changes: 62 additions & 6 deletions Classes/DetailPodcast.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@

#import "DetailPodcast.h"
#import "RootViewController.h"
#import <SystemConfiguration/SCNetworkReachability.h>

@implementation DetailPodcast

- (void) viewDidLoad {
[super viewDidLoad];
NSString *extension = [[[self story] link] pathExtension];
if ([extension isEqualToString:@"mp4"] || [extension isEqualToString:@"m4v"]
|| [extension isEqualToString:@"mov"])
[thumbnailButton addTarget:self action:@selector(playMovie) forControlEvents:UIControlEventTouchUpInside];
}

- (NSString *) rightBarButtonTitle {
return nil;
Expand All @@ -42,13 +50,61 @@ - (UIImage *) thumbimage {
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSString *urlString = [[request URL ] absoluteString];
if ([urlString rangeOfString:@".m"].location !=NSNotFound){
//[self playMovieAtURL:[NSURL URLWithString:[[self story] link]]];
{
// :below:20091018 We don't allow any links to be clicked here
if (navigationType == UIWebViewNavigationTypeOther)

return YES;
else
return NO;
}
return YES;
}

-(void)playMovieAtURL:(NSURL*)theURL

{
[theMovie release];
// theMovie is an iVar just for the sake of the analyzer...
theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
theMovie.scalingMode=MPMovieScalingModeAspectFill;

// Register for the playback finished notification.

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];

// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}

// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];

// Release the movie instance created in playMovieAtURL
[theMovie release];
theMovie = nil;
}

- (IBAction) playMovie {
SCNetworkReachabilityRef reachabilityRef = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, "apfeltalk.de");
SCNetworkReachabilityFlags flags;
BOOL success = SCNetworkReachabilityGetFlags(reachabilityRef, &flags);
CFRelease(reachabilityRef);
if (success == NO || (flags & kSCNetworkReachabilityFlagsIsWWAN) == kSCNetworkReachabilityFlagsIsWWAN) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString (@"Mobiles Netzwerk", @"")
message:NSLocalizedString (@"Videos sind nicht über ein mobiles Netzwerk verfügbar. Bitte verbinden Sie sich mit einem WLAN.Netzwerk", @"")
delegate:nil cancelButtonTitle:NSLocalizedString (@"OK", @"")
otherButtonTitles:nil];
[alert show];
[alert release];
}
else
[self playMovieAtURL:[NSURL URLWithString:[[self story] link]]];
}

- (void) dealloc
Expand Down
3 changes: 1 addition & 2 deletions Classes/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@interface DetailViewController : UIViewController <UIWebViewDelegate> {
IBOutlet UILabel *datum;
IBOutlet UILabel *lblText;
IBOutlet UIImageView *thumbnail;
IBOutlet UIButton *thumbnailButton;
IBOutlet UIScrollView *scrollView2;
IBOutlet UITextView *sunText;
IBOutlet UINavigationBar *Textvar;
Expand All @@ -39,7 +39,6 @@
IBOutlet UIImageView *detailimage;

Story *story;
MPMoviePlayerController* theMovie;
UIActionSheet *myMenu;
}
@property (readwrite, retain) Story *story;
Expand Down
44 changes: 1 addition & 43 deletions Classes/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ - (void)viewDidLoad {
}
[dateFormatter release];

[thumbnail setImage:[self thumbimage]];
[thumbnailButton setBackgroundImage:[self thumbimage] forState:UIControlStateNormal];

//Set the title of the navigation bar
//-150x150
Expand All @@ -183,48 +183,6 @@ - (void)viewDidLoad {
[webview release];
}

-(void)playMovieAtURL:(NSURL*)theURL

{
[theMovie release];
// theMovie is an iVar just for the sake of the analyzer...
theMovie=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
theMovie.scalingMode=MPMovieScalingModeAspectFill;

// Register for the playback finished notification.

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];

// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}

// When the movie is done,release the controller.
-(void)myMovieFinishedCallback:(NSNotification*)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:theMovie];

// Release the movie instance created in playMovieAtURL
[theMovie release];
theMovie = nil;
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint([thumbnail frame], location)) {
if ([[[self story] link] rangeOfString:@".mp4"].location !=NSNotFound || [[[self story] link] rangeOfString:@".m4v"].location !=NSNotFound){
[self playMovieAtURL:[NSURL URLWithString:[[self story] link]]];
}
}
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
Expand Down
Loading

0 comments on commit 4f128a0

Please sign in to comment.