Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Greetings - I've been trying to stream a single mp3 to an app for days now. There are no working examples anywhere it seems, and this baffles me! Can it be true? I can play "system sounds" easy, but not a full mp3. The only thing working so far, is working backwards and stripping out things from the SpeakHere sample app. That is an exercise!

So the question is for the gurus - what will it take for us programmers just getting into Cocoa, to get a nice simple sample? ! From the other posts I've seen I think someone might be willing to donate an icon. I'd probably toss out a void. Thanks.
 

JWBlue

macrumors member
Aug 21, 2008
33
0
Greetings - I've been trying to stream a single mp3 to an app for days now. There are no working examples anywhere it seems, and this baffles me! Can it be true? I can play "system sounds" easy, but not a full mp3. The only thing working so far, is working backwards and stripping out things from the SpeakHere sample app. That is an exercise!

So the question is for the gurus - what will it take for us programmers just getting into Cocoa, to get a nice simple sample? ! From the other posts I've seen I think someone might be willing to donate an icon. I'd probably toss out a void. Thanks.

Try this

http://www.idevgames.com/forum/showthread.php?t=15280
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Thanks for the quick response. It failed for me, here's what I did.

I started a new blank window based application. I added an NSObject subclass to the project, named it GBMusicTrack, it made the .h file too of course. There was an import of AppKit.h, and the compiler wasn't finding it. I assumed that was maybe something replaced by Foundation or something in Cocoa, and removed the import. The project compiles without error until I add the call lines. The forum thread doesn't really say where to put those lines either, and I put them in the applicationDidFinishLaunching() method. It is this chunk that I get errors from:

Code:
GBMusicTrack *song = [[GBMusicTrack alloc] initWithPath:[[NSBundle mainBundle] pathForResource:@"WarChant" ofType:@"mp3"]];
	[song setRepeat:YES];
	[song play];

error: 'GBMusicTrack' undeclared(first use in this function) 
error: 'song' undeclared(first use in this function)

Am I putting "the code" as he calls it, in the wrong place? Do I simply need to declare that stuff and if so, where? Thanks...
 

SqueegyX

macrumors regular
Mar 24, 2008
108
1
Use the sound engine from the Crash Landing example. Its pretty robust, and has support for both music and localized sound effects.

EDIT: Also, in the above example, try replacing the Appkit.h require with a UIKit.h instead.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
I did add the UIKit.h import, no affect. I'm looking for the Crash Landing example...can someone point me to it? Thx.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Cool, thanks for the link. I did try the oalTouch sample too and it wouldn't run in the simulator for me. I'll look at this Crash Landing one now. Thx.

EDIT.
Crash Landing only on device, I only have simulator. My company hasn't yet paid for the developer license and therefore I can't transfer to a device. It looks like I may be able to dig out what I need...
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Uh, ok....I'm a complete TOOL. If the Crash Landing project is something I should be able to deconstruct, or even remotely understand, I am in the wrong place! That is the most complicated thing I've seen yet. The more I learn, the harder this gets. Thx.
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Uh, ok....I'm a complete TOOL. If the Crash Landing project is something I should be able to deconstruct, or even remotely understand, I am in the wrong place! That is the most complicated thing I've seen yet. The more I learn, the harder this gets. Thx.

Yep, it's pretty nasty I'm afraid. If you just want to play an mp3 and don't care about what's on the screen, you could try MPMoviePlayerController instead (https://developer.apple.com/iphone/...PlayerController/MPMoviePlayerController.html), which is far simpler:

Code:
NSString *url = @"http://www.example.com/path/to/song.mp3";
MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Seriously? You can use the media player for an mp3? First I've heard of that. Yes, my task is that simple. I just need to play an mp3. Don't even need t stop it!!!

I'll have a look at this one. Thanks again, I really appreciate your advice.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
...the link you reference to the Class - doesn't list MP3, only video codecs. Is it simply unlisted?

Also - you provided what looks like the implement code, that I would place I assume in the appFinishedLaunching() method ? I would include/import the MediaPlayer framework. Is there anything else I would need to do to make that code work?
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
...the link you reference to the Class - doesn't list MP3, only video codecs. Is it simply unlisted?

Yup; works fine for me :)

.Also - you provided what looks like the implement code, that I would place I assume in the appFinishedLaunching() method ? I would include/import the MediaPlayer framework. Is there anything else I would need to do to make that code work?

That's it really. Import the framework and #import <MediaPlayer/MediaPlayer.h>in your header. Apple have some sample code which includes examples of notifications here: https://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/index.html. In their example they're loading a local file, but URLs as in the above example work fine too.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Local file is fine. One more question as I start into this one, it reads:
If you use this class to play audio files, it displays a black screen while the audio plays.

Does it only display a black screen, period? That would suffice I think, but realy need a static image to show while playing. No interaction though.
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
On the device it will show the QuickTime logo and a few interface bits (volume control, position in audio, play/pause, exit); the simulator is a bit variable! Unfortunately you don't get to control the background image, though I guess you could replace the mp3 with a video that has a still-image background as a quick fix.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Started blank project. Opened AppDelegate.m file, added the include, and added the code referenced above wihtin the applicationDidFinishLaunching: method. I got 4 errors.

Code:
NSString *url = @"Florida_State_War_Chant.mp3";
	MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
	[moviePlayer play];


error: variable sized oject can not be initiated
error: statically allocated instance of Obj-C class 'MPMoviePlayerController'
error: statically allocated instance of Obj-C class 'MPMoviePlayerController'
error: cannot convert to a pointer type

?
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Started blank project. Opened AppDelegate.m file, added the include, and added the code referenced above wihtin the applicationDidFinishLaunching: method. I got 4 errors.

Code:
NSString *url = @"Florida_State_War_Chant.mp3";
	MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
	[moviePlayer play];


error: variable sized oject can not be initiated
error: statically allocated instance of Obj-C class 'MPMoviePlayerController'
error: statically allocated instance of Obj-C class 'MPMoviePlayerController'
error: cannot convert to a pointer type

?

For a local file you need to follow the example from the sample code (https://developer.apple.com/iphone/library/samplecode/MoviePlayer_iPhone/index.html), i.e.:

Code:
NSString *url = [[NSBundle mainBundle] pathForResource:@"Florida_State_War_Chant" ofType:@"mp3"];
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
For now, file can be local or remote. Either way - I get the same errors.

Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after application launch
    [window makeKeyAndVisible];
	
	NSString *url = @"http://www.limitedwave.com/mp3/FailingForward.mp3";
	MPMoviePlayerController moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
	[moviePlayer play];	
}

I zipped and attached my test project. Feel free to send whatever you have working back at me. I hate to keep pestering you with this back and forth, I'm sure you have better things to do!
 

Attachments

  • PlayIt.zip
    192.7 KB · Views: 130

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
You need to import the MoviePlayer framework itself into your project (Add > Existing Frameworks...).

Also, MPMoviePlayerController moviePlayer should be MPMoviePlayerController *moviePlayer since it's not static.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Almost there huh! Man - I can't import the MoviePlayer Framework cause it isn't there! ? Not sure what's going on with that. I d/l'd and installed all of this within the last 7 days. Attached is a screen shot of what see in that dialog...
 

Attachments

  • Picture 1.png
    Picture 1.png
    213.6 KB · Views: 98

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
...I located the media player framework, still no MPMoviePlayer framework.

Attached screen shot of the current, single error:
 

Attachments

  • Picture 2.png
    Picture 2.png
    64.9 KB · Views: 101

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
Most of the OP's problems have nothing to do with audio. They have to do with knowing how to write Obj-C apps. I suggest basic Obj-C and Cocoa tutorials until you have them down pat in your sleep. Then the OP will know were all the pieces (declarations, functions, frameworks, library includes, pointer references, etc., etc.) go. There are dozens and dozens of "silly" little Obj-C details which are trivial to get right when you know what your doing, and always end up in the wrong place if you don't.


YMMV.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
Thanks for the advice senor firewood. I couldn't agree with you more. My reality is this - for starters, I can barely decode your response. That's barely English to me! In general, I learn better by doing. I have spent one day working through the Object Oriented Programming primer, a day on the Obj-C primer, a day on the Cocoa primer, and then a week building small Hello World type apps - subbing text strings, triggering methods on orientation changes, simple stuff. The task at hand for me is to simply play an audio file at the touch of a button, change of orientation or change in acceleration. This is just one task among many for me, and for this one I am fast running out of time! I don't like to fail at things, so likely I'll be hammering at this after work hours for some time to come, if i do in fact fail. Right now I'm hoping Mr. jnic might continue to work me through my problem.

If anyone has a simple project in which a complete audio file can be triggered and player, please zip and post it! I'm not the only person who'd wet their pants for that. Thx.
 

limitedwave

macrumors newbie
Original poster
Nov 11, 2008
16
0
OP, you're missing the star in MoviePlayer *moviePlayer.

I added the star...though I don't see the exact line you speak of.

Current Code:
Code:
NSString *url = @"http://www.limitedwave.com/mp3/FailingForward.mp3";
	MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
	[moviePlayer play];

...gives me the attached error(image).

What/who is OP?
 

Attachments

  • Picture 3.png
    Picture 3.png
    55.6 KB · Views: 97
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.