Copy link to clipboard
Copied
Ok so I will explain the two problems I am having with my Media Player at the moment and I hope I can explain it clear enough for anyone to understand
Problem #1:
I was getting an error which was error #1009 null object reference etc etc etc...
I fixed that by adding the following lines:
my_sound = new Sound();
my_channel = new SoundChannel();
Now I am getting another error which seems to be because I am streaming mp3's from a external .xml file which I am loading into my media player with the URLLoader.
The error I am getting now is:
ArgumentError: Error #2068: Invalid sound.
at flash.media::Sound/play()
at BasicPlayer_fla::MainTimeline/dropIt2()[BasicPlayer_fla.MainTimeline::frame1:378]
Which I may be wrong saying this but I believe I am getting this error as the audio is being streamed and the variable for what I previously had in my code:
var my_sound:Sound;
var my_channel:SoundChannel;
I had these variables already stated to hold my sound and soundchannel objects.
The error is at line 378:
// function dropIT2
// dropping slider
function dropIt2(e:Event):void
{
if (song_paused == false)
{
if (isDragging == true)
{
stopDrag();
var fullTime:int = Math.floor(my_sound.length/1000);
//my_sound.length:int = Math.ceil(my_sound.length /(my_sound.bytesLoaded / my_sound.bytesTotal));
var newPos:Number = fullTime/685.5 * Math.floor(seekBar_mc.sliderSeek_mc.x * 1000);
pausePosition = newPos/2;
my_channel.stop();
gotoAndPlay(2);
my_channel = my_sound.play(newPos); <------ Line 378
song_paused = false;
isDragging = false;
}
}else
{
isDragging = false;
seekBar_mc.sliderSeek_mc.stopDrag();
pausePosition = fullTime / 100 * Math.floor(seekBar_mc.sliderSeek.mc.x * 1000);
//seekBar_mc.sliderSeek_mc.visible = false;
}
}
How can I fix this if I am streaming audio with an .XML external file which I created with Dreamweaver.
Problem #2:
Ok and onto the second problem.
Whenever I try to run my mediaplayer with the following code it was working and the scrubber bar was moving automatically with the song in my ENTER_FRAME function. Now it doesn't and when I go to play a song the trackknob is stuck in a spot along my scrubber bar like it is glitched or something???
Here is my media player and as you can see when I start the song with the playSong() function the trackknob doesn't start at the start of the scrubber bar.
Here is my enterframe function:
// Add listener to trigger [onEnterFrame] function below
addEventListener(Event.ENTER_FRAME, onEnterFrame);
function onEnterFrame(event:Event):void
{
// Get full time
var tallytime = (my_sound.length/1000);
var totalmins:Number = Math.floor(tallytime /60);
var totalsecs = Math.floor (tallytime) % 60;
if (totalsecs < 10)
{
totalsecs = "0" + totalsecs;
}
timerText_txt.text = ( " " + totalmins+ ":" + totalsecs);
// End get playing time
// Get playing time
var totalSeconds:Number = my_channel.position/1000;
var minutes:Number = Math.floor(totalSeconds /60);
var seconds = Math.floor (totalSeconds) % 60;
if (seconds < 10)
{
seconds = "0" + seconds;
}
completeText_txt.text = ( " " + minutes+ ":" + seconds);
// End get Full time
/// progress bar code...
var estimatedLength:int = Math.ceil(my_sound.length / (my_sound.bytesLoaded / my_sound.bytesTotal));
var playbackPercent:uint = 100 * (my_channel.position / estimatedLength );
// I want my position bar to be 200 pixels wide on completion so I multiply the percentage x 2
seekBar_mc.sliderSeek_mc.x = playbackPercent * 2;
seekBar_mc.sliderSeek_mc.x = seekBar_mc.sliderSeek_mc.x;
// make the loaded progress bar that lives under the playhead progress bar grow dynamically
var loadedPercent:uint = 100 * (my_sound.bytesLoaded / my_sound.bytesTotal);
seekBar_mc.sliderSeek_mc.x = loadedPercent * 2;
}
How can I go about fixing this any help is appreciated thank-you.
Copy link to clipboard
Copied
to start, it doesn't appear my_sound has any actual associated sound. ie, you're not using a sound class from your library and you're not loading a sound using my_sound.
Copy link to clipboard
Copied
Yeah I am not loading a sound using my_sound but it have the my_sound variable to hold a sound object for my media player, I am loading sounds into my Media Player using a XML List.
// function playSong
function playSong(mySong:Number):void
{
// extract the song details from the song XML data node
// use the @ sign to retrieve the attributes an XML node
// store the specific data in local variables.
// the value of mySong will be passed to the function when we call it:
var myTitle = my_songs[mySong].@TITLE;
var myArtist = my_songs[mySong].@ARTIST;
var myURL = my_songs[mySong].@URL;
songTitle_txt.text = myTitle; // display song title to text field on stage
songArtist_txt.text = myArtist; // display song artist to text field on stage
// test if the channel has anything in it,
// if it does, then stop the channel and proceed with the rest of the code
// used by NEXT and PREVIOUS functions
if(my_channel)
{
my_channel.stop();
my_channel.removeEventListener(Event.SOUND_COMPLETE, onForward);
}
my_sound = new Sound(); // creates a new sound object
my_sound.load(new URLRequest(myURL)); // load the song object to stream
my_channel = my_sound.play(); // stream the song file into the sound channel
my_channel.addEventListener(Event.SOUND_COMPLETE, onForward); // when current song stops, play next song
If you see in my playSong Function I have already created a new sound object and then I am loading a URL request from my XML List.
Copy link to clipboard
Copied
again, if
my_channel = my_sound.play(newPos);
executes before an mp3 completes loading into my_sound, you will trigger a 2068 invalid sound error.
Copy link to clipboard
Copied
#1:
you might have a problem in your dropIt2 fucntion:
you are using an anonymously
stopDrag()
and later on (in the same function:)
seekBar_mc.sliderSeek_mc.stopDrag();
without having insight in how your dragging/dropping is supposed to work I can only guess that both refer to the same object(?)
if, you should use sth like:
e.currentTarget.stopDrag();
#2:
if you are using mp3 files to stream you can`t calculate the length of the sound file with this formula:
var estimatedLength:int = Math.ceil(my_sound.length / (my_sound.bytesLoaded / my_sound.bytesTotal));
since mp3 (and most lossy codecs) don`t distribute their filesize uniformly over the runtime (you would have to use a lossless format like wav for that to work)
so you will have to include the runtime of your playlists`songs into the xml files which you can then use:
var myDURATION = my_songs[mySong].@DURATION;
Find more inspiration, events, and resources on the new Adobe Community
Explore Now