MediaPlayer Using DropBox URL to play video - ios

Hi im creating an app for a uni project which requires me to play videos from a server.
i've decided to use Dropbox. However it would not play the file, is there any way for me to do it? or do i need to get the video from somewhere else.
ive tried another link which works perfectly fine. (not dropbox however)
http://www.jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v
my Coding Below
AnimeWatchViewController.m
//
// AnimeWatchViewController.m
// VideoPlayer
//
// Created by Alex Lee on 27/04/2014.
// Copyright (c) 2014 Alex Lee. All rights reserved.
//
#import "AnimeWatchViewController.h"
#interface AnimeWatchViewController ()
#end
#implementation AnimeWatchViewController
#synthesize moviePlayer;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(IBAction)playMovie{
NSURL * url =[[NSURL alloc] initWithString:#"https://www.dropbox.com/s/t05zdw2woogo4kh/ACW_3.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(20, 100, 275, 150)];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
moviePlayer.allowsAirPlay = YES;
moviePlayer.shouldAutoplay = YES;
moviePlayer.controlStyle = MPMovieControlModeDefault;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
AnimeWatchViewController.h
//
// AnimeWatchViewController.h
// VideoPlayer
//
// Created by Alex Lee on 27/04/2014.
// Copyright (c) 2014 Alex Lee. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface AnimeWatchViewController : UIViewController
#property(nonatomic,strong) MPMoviePlayerController * moviePlayer;
-(IBAction)playMovie;
#end

You're using the URL https://www.dropbox.com/s/t05zdw2woogo4kh/ACW_3.mp4, but that's not a link to a video... it's a link to a page with a video on it.
To convert it to a direct link to the video, change www.dropbox.com to dl.dropboxuser.com, like this: https://dl.dropboxusercontent.com/s/t05zdw2woogo4kh/ACW_3.mp4

for that you have to first get direct download link then you can play video directly from dropbox server
Try to understand this link may help you

Related

Video does not play from viewDidLoad

I am building an iPhone 6 app for a friend's store. I wanted to have a video intro automatically playing when the initial view controller starts. I get no sound or audio.
I have on my storyboard a UIViewController, and in it a view that I re-classified as AVPlayerClass
I have also added added cupcake1.mov (QuickTime format) under "Supporting Files".
// AppDelegate.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
//
// AppDelegate.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
#end
//
// ViewController.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import "AVPlayerClass.h"
#class AVPlayer;
#class AVPlayerClass;
#interface ViewController : UIViewController
#property (nonatomic, strong) AVPlayer *player;
#property (nonatomic, strong) AVPlayerClass *playerView;
#end
//
// ViewController.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize player;
#synthesize playerView;
- (void)viewDidLoad {
[super viewDidLoad];
[self setupMovie];
}
- (void)setupMovie
{
NSURL *url = [[NSBundle mainBundle]URLForResource:#"cupcake1" withExtension:#"mov"];
self.player = [AVPlayer playerWithURL: url];
[self.playerView setMovieToPlayer:player];
[self.player play];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
//
// AVPlayerClass+.h
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#class AVPlayer;
#interface AVPlayerClass : UIView
#property (nonatomic, retain) AVPlayer* player;
- (void)setMovieToPlayer:(AVPlayer*)player;
#end
//
// AVPalyerClass.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import "AVPlayerClass.h"
#implementation AVPlayerClass
+ (Class)layerClass
{
return [AVPlayerLayer class];
}
-(AVPlayer*)player
{
return [(AVPlayerLayer*) [self layer] player];
}
- (void)setMovieToPlayer:(AVPlayer *)player
{
[(AVPlayerLayer*)[self layer] setPlayer: player];
}
#end
//
// main.m
// MovieUIView
//
// Created by Daniel Habshush on 28.03.15.
// Copyright (c) 2015 H Company. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[]) {
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I just created a sample project just like yours and have my movie playing and used the MPMoviePlayerController class.
I launched Xcode and created a new iOS application project based on the Single View Application template.
I took a random sample movie file from vimeo, downloaded it, and copied it to my project calling it "movie.mp4".
In the ViewController.m I followed the following three steps:
#import <MediaPlayer/MediaPlayer.h>>
added a movieplayer property:
#property (nonatomic) MPMoviePlayerController *moviePlayer;
in viewDidLoad I added the following code:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"movie" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoPath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
self.moviePlayer.controlStyle = MPMovieControlStyleDefault;
self.moviePlayer.shouldAutoplay = YES;
[self.moviePlayer setFullscreen:YES animated:YES];
UIView *videoView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
[self.moviePlayer.view setFrame:videoView.bounds];
[videoView addSubview:self.moviePlayer.view];
[self.view addSubview:videoView];
[self.moviePlayer prepareToPlay];
[self.moviePlayer play];
}
I built and run and I am able to watch the movie and go fullscreen.
I tested on device and the movie plays.
If you get this far then you can adjust to your specific UI.
Hope this helps.

UIWebView not appearing - Xcode 6

my project won't show the web view no matter what code i try use. I even tried a youtube tutorial. I know this question has been asked many times but it doesn't make sense to me. I used this tutorial https://www.youtube.com/watch?v=AmMF7hWrYZk
Heres my code
If you need more detail please ask me. I'm knew to objective c
ViewController.m
// FirstViewController.m
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://google.com"];
NSURLRequest *requestURL = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
ViewController.h
//
// FirstViewController.h
// Have Your Say
//
// Created by Cormac on 11/1/14.
// Copyright (c) 2014 MK Software Corporation. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIWebView *webView;
#end

NSLog not working when I make a method call in objective c

I'm working on my first ground-up iOS app. I'm sure I'm doing something wrong here, but I can't seem to ferret out the problem.
I have an app with some IBActions in it, which do two things:
1) Outputs some simple text via NSLog (to let me know the action worked) - this works okay (it outputs my text via NSLog)
2) Makes a call to a method in a custom class which should also output an NSLog statement. - this doesn't work (no text output via NSLog)
I'm also struggling a bit with where to create the instances of my classes so that they are accessible elsewhere in my code.
Here's the code:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController {
// Variables that you want to access globally go here?
Player *wizard;
Orc *grunty;
}
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
and
//
// ViewController.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "ViewController.h"
#import "Player.h"
#interface ViewController ()
#end
#implementation ViewController
-(IBAction)takePie:(id)sender{
// Player attempts to take the pie
// If Orc's health is > 0, don't let the player take the pie
// If the Orc's health is <= zero, let the player take the pie
NSLog(#"IBAction - player attempted to take the pie.");
[wizard takePie];
}
-(IBAction)castFireball:(id)sender{
NSLog(#"IBAction - player cast fireball.");
[wizard castFireball];
}
-(IBAction)attack:(id)sender{
NSLog(#"IBAction - player attacked.");
[wizard attackOrc];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
Player *wizard = [[Player alloc]init];
Orc *grunty = [[Orc alloc]init];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and
//
// Player.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <Foundation/Foundation.h>
#interface Player : NSObject
#property int maxHealth;
#property int currentHealth;
#property int armorClass;
#property int meleeToHitModifier;
-(void)setHeathBar;
-(void)attackOrc;
-(void)castFireball;
-(void)takePie;
#end
and
//
// Player.m
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import "Player.h"
#implementation Player
#synthesize maxHealth;
#synthesize currentHealth;
#synthesize armorClass;
#synthesize meleeToHitModifier;
-(void)setHealthBar {
NSLog(#"Player health is 15");
return;
}
-(void)attackOrc {
// roll a d20
// add the "to hit" modifier
// compare the result to the orc's armor class
NSLog(#"Player - Player attached the Orc");
return;
}
-(void)castFireball{
NSLog(#"Player - Player casts Fireball");
return;
}
-(void)takePie{
NSLog(#"Player - Player attempts to take pie");
return;
}
#end
Note: I also have an Orc class defined, but it looks fairly identical to the player class shown.
Thanks in advance for the help!
-- Eddie
Your ViewController.h (which you should call by some more distinctive name, FYI) should look like this:
//
// ViewController.h
// OrcAndPie
//
// Created by me on 4/27/13.
// Copyright (c) 2013 me. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "Player.h"
#import "Orc.h"
#interface ViewController : UIViewController
#property Player *wizard;
#property Orc *grunty;
-(IBAction)takePie:(id)sender;
-(IBAction)castFireball:(id)sender;
-(IBAction)attack:(id)sender;
#end
Then in your ViewController.m, your viewDidLoadMethod should look like:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.wizard = [[Player alloc]init];
self.grunty = [[Orc alloc]init];
}
This should at least ensure you have an instantiated instance of Player that you can call methods on, so your NSLog should be reached.

iOS: Playing a video on application launch

I am new to Xcode so I've been trying to follow along to tutorials but haven't come across any that explain what I'm trying to achieve. I just want to play a video automatically when you open an application. I have it somewhat working in that the audio plays, but I cannot see any video. Am I missing something? I am getting this Warning in my output window:
Warning: Attempt to present MPMoviePlayerViewController: 0x831d7a0 on ViewController: 0x9d10540 whose view is not in the window hierarchy!
In my ViewController.h:
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
#interface ViewController : UIViewController
#end
ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url =[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Placeholder" ofType:#"mp4"]];
MPMoviePlayerViewController *playercontroller = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playercontroller];
playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playercontroller.moviePlayer play];
playercontroller = nil;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Instead of
[playercontroller.moviePlayer play];
do
[playercontroller play];
Side note:
Also check up on your naming convention. In Objective-C variable names "should" have capital letter on each new word in the variable. E.g. instead of playercontroller use playerController.
I know your status.
it's warning from Xcode.
So, you just change the code.
like this,
[playercontroller performSelector:#selector(player)];

UIWebView in tabbed application (Xcode)

I'm just starting to learn Xcode, and have run in to some problems...
I've made a tabbed application in Xcode 4.3 which works as deired. But I previously made a simple UIWebView application, that I would now like to implement into one of the tabs on the new application.
This is what I've done in the classes for FirstViewController:
// FirstViewController.h
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController {
IBOutlet UIWebView *webDisplay;
}
#property(nonatomic,retain) UIWebView *webDisplay;
#end
And the FirstViewController.m:
// FirstViewController.m
// SafeLine
//
// Created by Camilla Fröberg on 2012-03-27.
// Copyright (c) 2012 SafeLine Sweden AB. All rights reserved.
//
#import "FirstViewController.h"
#interface FirstViewController ()
#end
#implementation FirstViewController
#synthesize webDisplay;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *urlAddress = #"http://www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[webDisplay loadRequest:requestObj];
[super viewDidLoad];
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#end
When running the application I won't get any error message, and it will not show the website, instead it will only show an empty view...
Any help is appreciated!
// Best regards
Camilla from Sweden
I think, you should check if you connected the UIWebView in the Interface Builder with IBOutlet.

Resources