Using the latest code of GPUImage from GitHub I tried the following:
#import "ViewController.h"
#import "GPUImage.h"
#import <AssetsLibrary/AssetsLibrary.h>
#interface ViewController ()
{
GPUImageOutput<GPUImageInput> *filter0;
GPUImageMovieWriter *movieWriter;
GPUImageMovie *movie1, *movie2;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"started");
NSURL *url = [[NSBundle mainBundle] URLForResource:#"video1" withExtension:#"MOV"];
movie1 = [[GPUImageMovie alloc] initWithURL:url];
movie1.playAtActualSpeed = YES;
NSURL *url2 = [[NSBundle mainBundle] URLForResource:#"video2" withExtension:#"MOV"];
movie2 = [[GPUImageMovie alloc] initWithURL:url2];
movie2.playAtActualSpeed = YES;
filter0 = [[GPUImageNormalBlendFilter alloc] init];
[filter0 forceProcessingAtSize:CGSizeMake(1080, 1920)];
[movie1 addTarget:filter0];
[movie2 addTarget:filter0]; // movie2 adding Filter
GPUImageView *filterView= (GPUImageView *) self.view;
filterView.fillMode = kGPUImageFillModePreserveAspectRatio;
[filter0 addTarget:filterView];
[movie1 startProcessing];
[movie2 startProcessing]; // movie2 startprocessing
}
#end
Basically, I want to blend two videos and display it on the screen, but after running, nothing gets displayed, only black screen is being shown and the first frame of the 2nd video is shown after few seconds.
** I have added the "Header Search Path" and also given the flag -ObjC in "Other Linkers"
Now if I add a PixellateFilter to any one of the video(say movie1, commenting movie2 adding Filter and movie2 startprocessing then the result is coming.
So my question is why the blend is not happening for two videos, am I doing something wrong.
Thanks in advance
NSURL *url = [[NSBundle mainBundle] URLForResource:#"abc" withExtension:#"mp4"];
gpuIM = [[GPUImageMovie alloc] initWithURL:url];
gpuIM.playAtActualSpeed = YES;
NSURL *url2 = [[NSBundle mainBundle] URLForResource:#"def" withExtension:#"mov"];
movie2 = [[GPUImageMovie alloc] initWithURL:url2];
movie2.playAtActualSpeed = YES;
filter0 = [[GPUImageColorDodgeBlendFilter alloc] init];
[gpuIM addTarget:filter0];
[movie2 addTarget:filter0];
[filter0 addTarget:_view0];
[gpuIM startProcessing];
[movie2 startProcessing];
Another approach would be create a avasset from URL , use it in GPUImageMovie,most importantly make the GPUImageMovie instance global.
Related
I'm adding a GIF image in UIWbeview in Objective-C. The problem is that the image size doesn't fit in the screen and the contents above the gif video is not showing. How can I adjust the image size and show the buttons above it.
My code is:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"back" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:#"gif" textEncodingName:NULL baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
// Do any additional setup after loading the view.
}
You can move your code to viewDidAppear
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"back" ofType:#"gif"];
NSData *gif = [NSData dataWithContentsOfFile:filePath];
UIWebView *webViewBG = [[UIWebView alloc] initWithFrame:self.view.frame];
[webViewBG loadData:gif MIMEType:#"image/gif" textEncodingName:#"UTF-8" baseURL:NULL];
webViewBG.userInteractionEnabled = NO;
webViewBG.scalesPageToFit=YES;
[self.view addSubview:webViewBG];
}
I need someone's help. Actually I have no idea what to replace to get a custom background image. I'm just can't do it anymore.
-(id) init
{
// always call "super" init
// Apple recommends to re-assign "self" with the "super's" return value
if( (self=[super initWithColor:ccc4(219,31,94, 999)]) ) {
ws=[[CCDirector sharedDirector]winSize];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:#"game" ofType:#"wav"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops=-1;
[player play];
Create and add a CCSprite:
CCSprite *bg = [CCSprite spriteWithFile:#"bg.png"];
bg.tag = 1;
bg.anchorPoint = CGPointMake(0, 0);
[self addChild:bg];
Ok so im pretty new to Xcode and am trying to make a simple app. i need my sound to keep looping and stop when i press the stop button. Please help and thanks in advance. here is my code so far.
as you can see the sound plays once then stops .
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
#synthesize Images;
-(IBAction)start:(id)sender;{
AudioServicesPlaySystemSound(PlaySoundID);
Images.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"Light.png"],
[UIImage imageNamed:#"Light1.png"],
[UIImage imageNamed:#"Light2.png"],
[UIImage imageNamed:#"Light3.png"], nil];
Images.animationRepeatCount = 99999999;
Images.animationDuration = .2;
[Images startAnimating];
[self.view addSubview:Images];
}
-(IBAction)stop:(id)sender;{
[Images stopAnimating];
}
- (void)viewDidLoad
{
NSURL *SoundURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"Siren" ofType:#"wav"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)SoundURL, &PlaySoundID);
[super viewDidLoad];
Images.image = [UIImage imageNamed:#"Light.png"];
[self.view addSubview:Images];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
NSURL *soundURL = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"Siren"
ofType:#"wav"]];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL
error:nil];
for "infinite" number of loops:
audioPlayer.numberOfLoops = -1;
I tried to play a video in iOS but it just played 5s for any video. This is my code:
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"videoviewdemo" ofType:#"mp4"];
NSURL *movieURL = [[NSURL alloc]initFileURLWithPath:moviePath];
MPMoviePlayerController *theMoviPlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMoviPlayer.controlStyle = MPMovieControlStyleFullscreen;
theMoviPlayer.controlStyle = MPMovieControlStyleDefault;
[theMoviPlayer setMovieSourceType:MPMovieSourceTypeFile];
theMoviPlayer.shouldAutoplay = YES;
theMoviPlayer.view.transform = CGAffineTransformConcat(theMoviPlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
[theMoviPlayer.view setFrame:self.view.frame];
[theMoviPlayer prepareToPlay];
[self.view addSubview:theMoviPlayer.view];
Declare an ivar #property (nonatomic,strong) MPMoviePlayerController *myMovieController;
assign theMoviPlayer to it as follows,
self.myMovieController = theMoviPlayer;
[self.view addSubview: self.myMovieController.view];
and then play the movie.
The issue seems to be that theMoviPlayer is not retained.
Here is my MainViewController.m
#import "MainViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize audioPlayer;
#synthesize soundsArray;
-(void)prepareSounds
{
NSString *filepath= [[NSBundle mainBundle] pathForResource:#"Sounds" ofType:#"plist"];
self.soundsArray = [[NSArray alloc] initWithContentsOfFile:filepath];
}
- (IBAction)playSound:(id)sender {
UIButton *buttonPressed = (UIButton *)sender;
NSString *soundName = [soundsArray objectAtIndex:(buttonPressed.tag -1)];
NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:#"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p = [[AVAudioPlayer alloc]
initWithContentsOfURL:file error:nil];
self.audioPlayer = p;
[self.audioPlayer play];
}
- (IBAction)playSound2:(id)sender {
UIButton *buttonPressed = (UIButton *)sender;
NSString *soundName = [soundsArray objectAtIndex:(buttonPressed.tag -2)];
NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:#"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p = [[AVAudioPlayer alloc]
initWithContentsOfURL:file error:nil];
self.audioPlayer = p;
[self.audioPlayer play];
}
- (IBAction)playSound3:(id)sender {
UIButton *buttonPressed = (UIButton *)sender;
NSString *soundName = [soundsArray objectAtIndex:(buttonPressed.tag -3)];
NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:#"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p = [[AVAudioPlayer alloc]
initWithContentsOfURL:file error:nil];
self.audioPlayer = p;
[self.audioPlayer play];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)showInfo:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
#end
My MainViewController.h
#import <UIKit/UIKit.h>
#import "FlipsideViewController.h"
#import <AudioToolbox/AudioToolbox.h>
#import <AVFoundation/AVFoundation.h>
#interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
AVAudioPlayer *audioPlayer;
NSArray *soundsArray;
}
#property(nonatomic, retain) AVAudioPlayer *audioPlayer;
#property(nonatomic, retain) NSArray *soundsArray;
-(void)prepareSounds;
- (IBAction)playSound:(id)sender;
- (IBAction)playSound2:(id)sender;
- (IBAction)playSound3:(id)sender;
#end
In the 'Supporting Files' folder I have an array of strings with the name of the sound files I want to play, and in the 'Supporting Files' folder I have a folder named 'Sounds', which contains the sound files.
All of my buttons play the same sound. Can someone please provide some insight. Thanks!
I think the problem may be in this line playSound:
NSString *soundName = [soundsArray objectAtIndex:(buttonPressed.tag -1)]
which is repeated in playSound2 and playSound3 with "buttonPressed.tag -2" and "buttonPressed.tag -3".
If your buttonPressed.tags are set to 1, 2, and 3, then each time "buttonPressed.tag -X" is likely evaluating to 0, and playing the sound of the first file in the array.
You are repeating the code to do the same task.
Add all your buttons IBAction to a single method (say it as playSound)
Implement the method like:
- (IBAction)playSound:(UIButton *)sender
{
NSString *soundName = [soundsArray objectAtIndex:(sender.tag -1)];
NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:#"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
self.audioPlayer = p;
[self.audioPlayer play];
}
There is no need of writing same code for each individual button.
SOLVED: prepareSounds() was never called. Here is the working code:
#import "MainViewController.h"
#interface MainViewController ()
#end
#implementation MainViewController
#synthesize audioPlayer;
#synthesize soundsArray;
-(void)prepareSounds
{
NSString *filepath= [[NSBundle mainBundle] pathForResource:#"Sound" ofType:#"plist"];
self.soundsArray = [[NSArray alloc] initWithContentsOfFile:filepath];
}
- (void)stopAudio
{
if (audioPlayer!= nil) {
[audioPlayer stop];
//do some task for changing the Image i.e setting the default image
}
}
- (IBAction)playSound:(UIButton *)sender
{
UIButton *btn = (UIButton*)sender;
NSString *soundName = [soundsArray objectAtIndex:(btn.tag - 1)];
NSString *path = [[NSBundle mainBundle] pathForResource:soundName ofType:#"mp3"];
NSURL *file = [[NSURL alloc] initFileURLWithPath:path];
AVAudioPlayer *p = [[AVAudioPlayer alloc] initWithContentsOfURL:file error:nil];
self.audioPlayer = p;
if([audioPlayer isPlaying])
{
[self stopAudio];
}
[self.audioPlayer play];
}
- (void)viewDidLoad
{
[self prepareSounds];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Flipside View
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)showInfo:(id)sender
{
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:#"FlipsideViewController" bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:controller animated:YES completion:nil];
}
#end